//此api文件为结束有弹窗使用api
(function() {
    var yisutui = {}; //创建一个对象
    var currentScreen;
    var scoreInfo = {
        currentRank: null,
        totalRank: null,
        ranklist: null
    };
    var xmlHttp;
    var host = window.location.host;
    var domain = "http://" + host;
    var marketing = ""; // 排行榜规则按钮隐藏
    var ystpage_index = 2; // 全部排行榜
    var ystpage_friend_index = 2; // 好友排行榜
    var ystred_index = 2; // 红包排行榜
    var ystred_friend_index = 2; // 好友红包排行榜
    var ystrank_flag = "more";
    var ystmygift = ""; // 抽奖按钮
    var ystmygift_down = ""; // 
    var yst_gift_bg = "";
    var yst_gift_colse = "";
    var mycouponbg = ""; // 我的优惠券
    var mycouponclose = ""; // 
    var mycouponicon = "";
    var mycoupontext = "";
    //排行榜活动规则相关图标
    var rankrulebg = "";
    var rankruleicon = "";
    var rankruleclose = "";
    var rankruleback = "";
    var rankruleleft = "";
    var rankruleright = "";
    var rankruleshadow = "";
    //兑奖相关图片
    var cashprizetopbg = "";
    var cashprizebg = "";
    var cashprizesubmit = "";
    //报名表单相关图片
    var enrolltopbg = "";
    var enrollbg = "";
    var enrollsubmit = "";

    var gamescore = 0; // 游戏分数
    var gamedomain = window.location.pathname; //获取文件路径
    var gamedomain2 = gamedomain.substr(5);
    if (parseInt(gamedomain2) > 0) {
        var itemid = gamedomain2;
    } else {
        var gamedomain2 = gamedomain.substr(14);
        var endlen = gamedomain2.indexOf("/");
        var itemid = gamedomain2.substring(0, endlen);
    }
    if(itemid==""){
        itemid=13900;
    }
    //var endlen=gamedomain2.indexOf("/");

    //ajax封装函数 ggb 20150922
    var Ajax = function() {
        function request(url, opt) {
            function fn() {}
            var async = opt.async !== false,
                method = opt.method || 'GET',
                encode = opt.encode || 'UTF-8',
                data = opt.data || null,
                success = opt.success || fn,
                failure = opt.failure || fn;
            method = method.toUpperCase();
            if (data && typeof data == 'object') { //对象转换成字符串键值对
                data = _serialize(data);
            }
            if (method == 'GET' && data) {
                url += (url.indexOf('?') == -1 ? '?' : '&') + data;
                data = null;
            }
            var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
            xhr.onreadystatechange = function() {
                _onStateChange(xhr, success, failure);
            };
            xhr.open(method, url, async);
            if (method == 'POST') {
                xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=' + encode);
            }
            xhr.send(data);
            return xhr;
        }

        function _serialize(obj) {
            var a = [];
            for (var k in obj) {
                var val = obj[k];
                if (val.constructor == Array) {
                    for (var i = 0, len = val.length; i < len; i++) {
                        a.push(k + '[]=' + encodeURIComponent(val[i]));
                    }
                } else {
                    a.push(k + '=' + encodeURIComponent(val));
                }
            }
            return a.join('&');
        }

        function _onStateChange(xhr, success, failure) {
            if (xhr.readyState == 4) {
                var s = xhr.status;
                if (s >= 200 && s < 300) {
                    success(xhr);
                } else {
                    failure(xhr);
                }
            } else {}
        }
        return {
            request: request
        };
    }();

    /**
     * 把表单内容转换为hash对象
     * @param {HTMLElement} form对象
     * @return {hash}
     * @example
     * formToHash(document.forms[0]);
     */
    function formToHash(form) {
        var hash = {},
            el;
        for (var i = 0, len = form.elements.length; i < len; i++) {
            el = form.elements[i];
            if (el.name == "" || el.disabled) continue;
            switch (el.tagName.toLowerCase()) {
                case "fieldset":
                    break;
                case "input":
                    switch (el.type.toLowerCase()) {
                        case "radio":
                            if (el.checked)
                                hash[el.name] = el.value;
                            break;
                        case "checkbox":
                            if (el.checked) {
                                if (!hash[el.name]) {
                                    hash[el.name] = [el.value];
                                } else {
                                    hash[el.name].push(el.value);
                                }
                            }
                            break;
                        case "button":
                            break;
                        case "image":
                            break;
                        default:
                            hash[el.name] = el.value;
                            break;
                    }
                    break;
                case "select":
                    if (el.multiple) {
                        for (var j = 0, lens = el.options.length; j < lens; j++) {
                            if (el.options[j].selected) {
                                if (!hash[el.name]) {
                                    hash[el.name] = [el.options[j].value];
                                } else {
                                    hash[el.name].push(el.options[j].value);
                                }
                            }
                        }
                    } else {
                        hash[el.name] = el.value;
                    }
                    break;
                default:
                    hash[el.name] = el.value;
                    break;
            }
        }
        form = el = null;
        return hash;
    };

    yisutui.test = function() {
        console.log(22);
        Ajax.request("/g/get_spread", {
            async: false,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: "9"
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                console.log(data.code);
            },
            failure: function() {
                console.log('failure');
            }
        });
        console.log(66);
    };
    //功能和jquery的append一致
    yisutui.append = function(ele, html) {
        var tmp = document.createElement('div'), //创建一个临时Element
            fragment = document.createDocumentFragment(); //创建一个口袋

        tmp.innerHTML = html; //解脱的源头

        for (var i = 0, children = tmp.children, len = children.length; i < len; i++) {
            fragment.appendChild(children[i]); //装米喽，把临时Element中的大米都装到口袋里
        }

        ele.appendChild(fragment); //插入

        children = null;
        fragment = null;
        tmp = null;

        return ele;
    };

    //加密函数
    function enmimi(str, operation, key, expiry) {
        var operation = operation ? operation : 'DECODE';
        var key = key ? key : '';
        var expiry = expiry ? expiry : 0;

        var ckey_length = 4;
        key = md5(key);

        var keya = md5(key.substr(0, 16));
        var keyb = md5(key.substr(16, 16));
        if (ckey_length) {
            if (operation == 'DECODE') {
                var keyc = str.substr(0, ckey_length);
            } else {
                var md5_time = md5(microtime());
                var start = md5_time.length - ckey_length;
                var keyc = md5_time.substr(start, ckey_length)
            }
        } else {
            var keyc = '';
        }
        var cryptkey = keya + md5(keya + keyc);

        var strbuf;

        if (operation == 'DECODE') {
            str = str.substr(ckey_length);
            strbuf = base64_decode(str);
            //string = b.toString();
        } else {
            expiry = expiry ? expiry + time() : 0;
            tmpstr = expiry.toString();
            if (tmpstr.length >= 10)
                str = tmpstr.substr(0, 10) + md5(str + keyb).substr(0, 16) + str;
            else {
                var count = 10 - tmpstr.length;
                for (var i = 0; i < count; i++) {
                    tmpstr = '0' + tmpstr;
                }
                str = tmpstr + md5(str + keyb).substr(0, 16) + str;
            }
            strbuf = str;
        }


        var box = new Array(256);
        for (var i = 0; i < 256; i++) {
            box[i] = i;
        }
        var rndkey = new Array();
        for (var i = 0; i < 256; i++) {
            rndkey[i] = cryptkey.charCodeAt(i % cryptkey.length);
        }
        for (var j = i = 0; i < 256; i++) {
            j = (j + box[i] + rndkey[i]) % 256;
            tmp = box[i];
            box[i] = box[j];
            box[j] = tmp;
        }
        var s = '';
        strbuf = strbuf.split('');
        for (var a = j = i = 0; i < strbuf.length; i++) {
            a = (a + 1) % 256;
            j = (j + box[a]) % 256;
            tmp = box[a];
            box[a] = box[j];
            box[j] = tmp;
            s += chr(ord(strbuf[i]) ^ (box[(box[a] + box[j]) % 256]));
        }

        if (operation == 'DECODE') {
            if ((s.substr(0, 10) == 0 || s.substr(0, 10) - time() > 0) && s.substr(10, 16) == md5(s.substr(26) + keyb).substr(0, 16)) {
                s = s.substr(26);
            } else {
                s = '';
            }
        } else {
            s = base64_encode(s);
            var regex = new RegExp('=', "g");
            s = s.replace(regex, '');
            s = keyc + s;
        }

        return s;
    }

    function time() {
        var unixtime_ms = new Date().getTime();
        return parseInt(unixtime_ms / 1000);
    }

    function microtime(get_as_float) {
        var unixtime_ms = new Date().getTime();
        var sec = parseInt(unixtime_ms / 1000);
        return get_as_float ? (unixtime_ms / 1000) : (unixtime_ms - (sec * 1000)) / 1000 + ' ' + sec;
    }

    function chr(s) {
        return String.fromCharCode(s);
    }

    function ord(s) {
        return s.charCodeAt();
    }

    function md5(str) {
        return hex_md5(str);
    }


    //游戏剩余次数为0 20151202 ggb
    yisutui.nohitnum = function(addnum) {
            var yisutui_ = document.getElementById('nohitnum');
            if (!yisutui_) {
                var yisutui__div = document.createElement('div');
                var yisutui__css = document.createElement('style');
                yisutui__div.id = 'nohitnum';
                yisutui__div.innerHTML = "<div class='yst_share_bg'><img src='" + domain + "/API/img/share.png' class='yst_share_bgimg'><div class='yst_share_text'><p class='text_p1'>很遗憾！你今天的游戏次数已用完</p><p class='text_p2'>邀请好友一起玩，可获得<span>" + addnum + "</span>次游戏机会</p></div></div>";
                yisutui__css.innerHTML = ".yst_share_bg{width: 100%; height: 100%; background-color: rgba(0,0,0,.6); position: fixed;top: 0; left: 0; z-index: 9995;} .yst_share_bgimg{position: fixed;top: 0; left: 0; width: 100%; height: 100%;} .yst_share_text{  position: fixed;z-index: 100;    top: 73%;width: 80%;left: 10%;text-align: center;} .text_p1{font-size: 1.4rem; font-weight:600;color: #FFF;  } .text_p2{color: #fdc504;font-size: 1.3rem; font-weight:600;} .text_p2 span{color: #045cfd;font-size: 1.7rem;font-weight:600;} .yst_share_arrow{position: fixed;top: 1%;left: 77%;width: 22%;}";
                var first = document.body.firstChild;

                document.body.insertBefore(yisutui__div, first);
                document.head.appendChild(yisutui__css);
            }
        }
        //加载页面 20150829 ggb
    yisutui.start = function() {

        var yisutui_ = document.getElementById('yisutui_start');

        if (!yisutui_) {
            Ajax.request("/g/get_spread", {
                async: false,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (parseInt(data.status) == 1) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'yisutui_start';
                        // 判断是否有开启分享限制
                        if (parseInt(data.ishare) == 2) {
                            var sharelimit = "<p class='lefttime'>剩余游戏次数：" + data.hitnum + "次</p>"
                        } else {
                            var sharelimit = "";
                        }
                        yisutui__div.innerHTML = "<div class='inner'><img src='' class='logo' id='loadpic' height='80'><p class='website' id='loadtext'></p><div class='roundblack' id='drawblack' style='font-family:Microsoft YaHei,Helvetica,Tahoma;'>0%</div><img src='" + domain + "/API/img/roundyel.png' class='roundyellow' id='drawyellow'><p class='loadtext'>游戏加载中...</p>" + sharelimit + "</div>"
                        yisutui__css.innerHTML = "html{font-size: 10px;} @media screen and (min-width:480px) and (max-width:639px) {html {font-size: 15px}} @media screen and (min-width:640px) and (max-width:719px) { html {font-size: 20px}} @media screen and (min-width:720px) and (max-width:749px) {html {font-size: 22.5px}} @media screen and (min-width:750px) and (max-width:799px) {html {font-size: 23.5px}} @media screen and (min-width:800px) and (max-width:959px) {html {font-size: 25px}} @media screen and (min-width:960px) and (max-width:1079px) {html {font-size: 30px}} @media screen and (min-width:1080px) {html {font-size: 32px}} body{margin:0;padding: 0;background: #080707;font-family: Microsoft YaHei,Helvetica,Tahoma;} button, html, input, select, textarea {font-family: Microsoft YaHei,Helvetica,Tahoma;} a,p,span,ul,ol,li,td{-webkit-tap-highlight-color:rgba(0,0,0,0);padding: 0;margin: 0;list-style-type:none;text-decoration: none;} .inner{width:100%;height:100%;z-index:99999;margin:0;padding: 0;background: #080707;position:fixed;} .roundblack{width:7.1rem;height:7.1rem;line-height: 100px;z-index:10;background:#080707;position:fixed;border-radius: 100%;color: yellow;left: 39.1%;float:left;text-align: center;-webkit-animation-timing-function: ease;-webkit-animation:myfirst 4s;} @-webkit-keyframes myfirst{0%   { left: 39.1%;} 100% {left:60%;}} .roundyellow{margin-top:1%;background:yellow;position:fixed;border-radius: 100%;left:40%;width:6.4rem;height:6.4rem} .logo{display: block; margin: 40% auto 5%; height: 6rem; width: auto;} .website{position: relative;width: 100%;text-align: center;font-weight: 700;font-size: 18px;color: #fff;margin-bottom:5%;} .loadtext{margin-top:30%;color: yellow;position: fixed;width: 100%;text-align: center;font-size: 1.5rem;font-weight: 700;} .lefttime{color: #ffffff;width: 100%;text-align: center;float: left;margin-top: 45%;font-size:1.2rem;}"

                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        if (data.status == "1") {
                            if (data.loadpic != "") {
                                document.getElementById("loadpic").src = domain + '/files/images/' + data.loadpic;
                            } else {
                                document.getElementById("loadpic").src = domain + "/API/img/logo.png";
                            }
                            if (data.loadtext != "") {
                                document.getElementById("loadtext").innerText = data.loadtext;
                            } else {
                                document.getElementById("loadtext").innerText = "";
                            }
                        } else {
                            document.getElementById("loadpic").src = domain + "/API/img/logo.png";
                            document.getElementById("loadtext").innerText = "";
                        }
                        //分享限制
                        if (parseInt(data.ishare) == 2) {
                            if (parseInt(data.hitnum) < 1) {
                                yisutui.nohitnum(data.addnum);
                            }
                        }
                    } else {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'yisutui_start';

                        yisutui__div.innerHTML = "<div class='inner'><img src='" + domain + "/API/img/logo.png' class='logo' id='loadpic' height='80'><p class='website' id='loadtext'></p><div class='roundblack' id='drawblack' style='font-family:Microsoft YaHei,Helvetica,Tahoma;'>0%</div><img src='" + domain + "/API/img/roundyel.png' class='roundyellow' id='drawyellow'><p class='loadtext'>游戏加载中...</p></div>"
                        yisutui__css.innerHTML = "html{font-size: 10px;} @media screen and (min-width:480px) and (max-width:639px) {html {font-size: 15px}} @media screen and (min-width:640px) and (max-width:719px) { html {font-size: 20px}} @media screen and (min-width:720px) and (max-width:749px) {html {font-size: 22.5px}} @media screen and (min-width:750px) and (max-width:799px) {html {font-size: 23.5px}} @media screen and (min-width:800px) and (max-width:959px) {html {font-size: 25px}} @media screen and (min-width:960px) and (max-width:1079px) {html {font-size: 30px}} @media screen and (min-width:1080px) {html {font-size: 32px}} body{margin:0;padding: 0;background: #080707;font-family: Microsoft YaHei,Helvetica,Tahoma;} button, html, input, select, textarea {font-family: Microsoft YaHei,Helvetica,Tahoma;} a,p,span,ul,ol,li,td{-webkit-tap-highlight-color:rgba(0,0,0,0);padding: 0;margin: 0;list-style-type:none;text-decoration: none;} .inner{width:100%;height:100%;z-index:99999;margin:0;padding: 0;background: #080707;position:fixed;} .roundblack{width:7.1rem;height:7.1rem;line-height: 100px;z-index:10;background:#080707;position:fixed;border-radius: 100%;color: yellow;left: 39.1%;float:left;text-align: center;-webkit-animation-timing-function: ease;-webkit-animation:myfirst 4s;} @-webkit-keyframes myfirst{0%   { left: 39.1%;} 100% {left:60%;}} .roundyellow{margin-top:1%;background:yellow;position:fixed;border-radius: 100%;left:40%;width:6.4rem;height:6.4rem} .logo{display: block; margin: 40% auto 5%; height: 6rem; width: auto;} .website{position: relative;width: 100%;text-align: center;font-weight: 700;font-size: 18px;color: #fff;margin-bottom:5%;} .loadtext{margin-top:30%;color: yellow;position: fixed;width: 100%;text-align: center;font-size: 1.5rem;font-weight: 700;}"

                        var first = document.body.firstChild;


                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                    }

                },
                failure: function() {
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'yisutui_start';

                    yisutui__div.innerHTML = "<div class='inner'><img src='" + domain + "/API/img/logo.png' class='logo' id='loadpic' height='80'><p class='website' id='loadtext'></p><div class='roundblack' id='drawblack' style='font-family:Microsoft YaHei,Helvetica,Tahoma;'>0%</div><img src='" + domain + "/API/img/roundyel.png' class='roundyellow' id='drawyellow'><p class='loadtext'>游戏加载中...</p></div>"
                    yisutui__css.innerHTML = "html{font-size: 10px;} @media screen and (min-width:480px) and (max-width:639px) {html {font-size: 15px}} @media screen and (min-width:640px) and (max-width:719px) { html {font-size: 20px}} @media screen and (min-width:720px) and (max-width:749px) {html {font-size: 22.5px}} @media screen and (min-width:750px) and (max-width:799px) {html {font-size: 23.5px}} @media screen and (min-width:800px) and (max-width:959px) {html {font-size: 25px}} @media screen and (min-width:960px) and (max-width:1079px) {html {font-size: 30px}} @media screen and (min-width:1080px) {html {font-size: 32px}} body{margin:0;padding: 0;background: #080707;font-family: Microsoft YaHei,Helvetica,Tahoma;} button, html, input, select, textarea {font-family: Microsoft YaHei,Helvetica,Tahoma;} a,p,span,ul,ol,li,td{-webkit-tap-highlight-color:rgba(0,0,0,0);padding: 0;margin: 0;list-style-type:none;text-decoration: none;} .inner{width:100%;height:100%;z-index:99999;margin:0;padding: 0;background: #080707;position:fixed;} .roundblack{width:7.1rem;height:7.1rem;line-height: 100px;z-index:10;background:#080707;position:fixed;border-radius: 100%;color: yellow;left: 39.1%;float:left;text-align: center;-webkit-animation-timing-function: ease;-webkit-animation:myfirst 4s;} @-webkit-keyframes myfirst{0%   { left: 39.1%;} 100% {left:60%;}} .roundyellow{margin-top:1%;background:yellow;position:fixed;border-radius: 100%;left:40%;width:6.4rem;height:6.4rem} .logo{display: block; margin: 40% auto 5%; height: 6rem; width: auto;} .website{position: relative;width: 100%;text-align: center;font-weight: 700;font-size: 18px;color: #fff;margin-bottom:5%;} .loadtext{margin-top:30%;color: yellow;position: fixed;width: 100%;text-align: center;font-size: 1.5rem;font-weight: 700;}"

                    var first = document.body.firstChild;


                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            });
        }

        var DW = document.documentElement.clientWidth;
        var DH = document.documentElement.clientHeight;
        var dryellow = document.getElementById('drawyellow');
        var drblack = document.getElementById('drawblack');
        if (DW != 0 && DH != 0) {
            dryellow.style.width = 0.2 * DW + "px";
            dryellow.style.height = 0.2 * DW + "px";
            drblack.style.width = 0.22 * DW + "px";
            drblack.style.height = 0.22 * DW + "px";
            drblack.style.lineHeight = 0.22 * DW + "px";
        }

        drblack.addEventListener("webkitAnimationEnd", function() {
            // drblack.style.display="none";
        });
        var process = 0;
        var timer = setInterval(function() {
            if (process >= 10) {
                clearInterval(timer);
                document.querySelector(".inner").style.display = "none";

            } else {
                process++;
                drblack.innerHTML = process * 10 + '%';
                if (process == 10) {
                    document.querySelector(".loadtext").innerHTML = "游戏加载完毕";
                }
            }
        }, 310);
    };

    yisutui.start();


    //游戏进度条
    yisutui.progress = function(loadVal) {
        var progress = document.querySelector(".progress");
        var bar = document.querySelector('.bar');
        var xx_info = document.querySelector('.xx_info');
        if (progress) {
            if (loadVal <= 100) {
                loadVal *= 10; //每次加10
                bar.style.width = loadVal + '%';
                bar.innerHTML = loadVal + '%';
            }
            progress.style.display = 'block'; //显示滚动条
            if (loadVal === 100) {

                xx_info.innerHTML = "游戏加载完毕";
                var yisutui_ = document.getElementById('yisutui_start'); //设置多少时间隐藏游戏load

                setTimeout("yisutui_start.style.display = 'none'", 3000); //setTimeout参数要加双引号
            }
        }
    };
    //游戏未完成分享
    yisutui.share = function() {
        Ajax.request(domain + '/wxshare/sample.php?url=' + window.location.href, {
            async: true,
            method: "GET",
            encode: "UTF-8",
            data: {
                itemid: "9"
            },
            success: function(xhr) {
                var response = JSON.parse(xhr.responseText);
                console.log(response);
                var appid = response.appId;
                var timestamp = response.timestamp;
                var nonceStr = response.nonceStr;
                var signature = response.signature;
                yisutui.shareFriends(appid, timestamp, nonceStr, signature);
            },
            failure: function() {
                console.log('failure');
            }
        });
    }

    yisutui.shareFriends = function(appid, timestamp, nonceStr, signature) {
        wx.config({
            debug: false,
            appId: "" + appid,
            timestamp: '' + timestamp,
            nonceStr: '' + nonceStr,
            signature: '' + signature,
            jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
        });
        //获取微信分享的相关设置信息 20150811 ggb
        Ajax.request("/g/getfailshare", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.status == 1) {
                    var info = data.title;
                    var desc = data.desc;
                    var shareimg = data.shareimg;
                    if (parseInt(data.fsmode) == 1&&data.failshareurl!="http://") {
                        shareurl = data.failshareurl;
                    } else {
                        shareurl = domain + '/g/w/' + itemid + '?fopenid=' + data.openid;
                    }
                } else {
                    var info = "你也可以免费制作微信营销游戏，快来试试！";
                    var desc = "在电脑上访问www.yisutui.com，马上免费制作营销游戏！";
                    var shareimg = "http://www.xxuc.cn/lfgimg/exoshare.png";
                    shareurl = domain + '/g/w/' + itemid + '?fopenid=' + data.openid;
                }
                wx.ready(function() {
                    wx.onMenuShareTimeline({
                        title: '' + desc,
                        link: shareurl,
                        imgUrl: '' + shareimg,
                        success: function() {
                            Ajax.request("/g/shareadd", {
                                async: true,
                                method: "POST",
                                encode: "UTF-8",
                                data: {
                                    itemid: itemid,
                                    isact:0
                                },
                                success: function(xhr) {
                                    var data = JSON.parse(xhr.responseText);
                                    if (data.status == 1) {
                                        console.log("分享成功！");
                                    } else {
                                        console.log("分享失败！");
                                    }
                                },
                                failure: function() {
                                    console.log("网络异常！");
                                }
                            });
                        }
                    });
                    wx.onMenuShareAppMessage({
                        title: '' + info,
                        desc: '' + desc,
                        link: shareurl,
                        imgUrl: '' + shareimg,
                        type: 'link',
                        success: function() {
                            Ajax.request("/g/shareadd", {
                                async: true,
                                method: "POST",
                                encode: "UTF-8",
                                data: {
                                    itemid: itemid,
                                    isact:0
                                },
                                success: function(xhr) {
                                    var data = JSON.parse(xhr.responseText);
                                    if (data.status == 1) {
                                        console.log("分享成功！");
                                    } else {
                                        console.log("分享失败！");
                                    }
                                },
                                failure: function() {
                                    console.log("网络异常！");
                                }
                            });
                        }
                    });
                });
            },
            failure: function() {
                var info = "你也可以免费制作微信营销游戏，快来试试！";
                var desc = "在电脑上访问www.yisutui.com，马上免费制作营销游戏！";
                var shareimg = "http://www.xxuc.cn/lfgimg/exoshare.png";
                wx.ready(function() {
                    console.log(info);
                    wx.onMenuShareTimeline({
                        title: '' + info,
                        link: '' + window.location.href,
                        imgUrl: '' + shareimg
                    });
                    wx.onMenuShareAppMessage({
                        title: '' + info,
                        desc: '' + desc,
                        link: '' + window.location.href,
                        imgUrl: '' + shareimg,
                        type: 'link'
                    });
                });
            }
        });
    }
    yisutui.share();

    //游戏结束页面
    yisutui.gameOver = function(score, highscore) {
        document.getElementById('yisutui_').style.display = "block";
        document.getElementById('yst-score').innerText = score;
        yisutui.ranksubmit(score); //提交到数据库
        Ajax.request("/g/getgameover", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                //分数没提交成功且当前分数大于历史分数时，显示当前分数
                if (parseInt(score) > parseInt(data.myscore)) {
                    var bestgamescore = score;
                } else {
                    var bestgamescore = data.myscore;
                }
                document.getElementById('bestscore').innerText = bestgamescore;
                document.getElementById('bestrank').innerText = data.myrank;
                gamescore = score;
                //是否开启分享限制
                if (parseInt(data.ishare) == 2) {
                    var sharelimit = data.hitnum + "次游戏机会";
                    document.getElementById('gamenum').innerText = sharelimit;
                    var hitnum = data.hitnum;
                    var addnum = data.addnum;
                } else {
                    var hitnum = "";
                    var addnum = "";
                }
                var oncemore = document.getElementById('gamemore');
                oncemore.addEventListener("touchstart", function() {
                    yisutui.more(hitnum, addnum)
                }, false);
                if (parseInt(data.marketing) == 0) { //抽奖
                    // document.getElementById('gamegetprize').ontouchstart="yisutui.getprize()";
                    var prizenum = "还有" + data.drawnum + "次中奖机会";
                    document.getElementById('prizenum').innerText = prizenum;
                    var gamegetprize = document.getElementById('gamegetprize');
                    gamegetprize.addEventListener("touchstart", yisutui.ptypeform, false);
                } else if (parseInt(data.marketing) == 1) { //优惠券
                    var prizenum = "还有" + data.drawnum + "次抽奖机会";
                    document.getElementById('prizenum').innerText = prizenum;
                    var getcoupon = document.getElementById('getcoupon');
                    getcoupon.addEventListener("touchstart", yisutui.ctypeform, false);
                } else if (parseInt(data.marketing) == 2) { //报名表单
                    // var getmform = document.getElementById('getmform');
                    // getmform.addEventListener("touchstart", function() {
                    //     yisutui.mform()
                    // }, false);
                } else if (parseInt(data.marketing) == 5) { //微信红包
                    var getmred = document.getElementById('getmred');
                    //移除监听事件
                    if (getmred.removeEventListener) { // // 所有浏览器，除了 IE 8 及更早IE版本
                        getmred.removeEventListener("touchstart", yisutui.moreclicktip, false);
                    } else if (getmred.detachEvent) { // IE 8 及更早IE版本
                        getmred.detachEvent("touchstart", yisutui.moreclicktip);
                    }
                    //增加监听事件
                    getmred.addEventListener("touchstart", yisutui.getmred, false);
                }
            },
            failure: function() {
                document.getElementById('bestscore').innerText = score;
                document.getElementById('bestrank').innerText = "暂无排名";
                var oncemore = document.getElementById('gamemore');
                oncemore.addEventListener("touchstart", function() {
                    yisutui.more()
                }, false);
            }
        });

        yisutui.successshare(score);

    };
    //判断抽奖在游戏中还是公众号 20160317 syq
    yisutui.ptypeform=function(){
        
        Ajax.request("/g/drawtype",{
            async:true,
            method:"POST",
            encode:"UTF-8",
            data:{
                itemid:itemid
            },
            success:function(xhr){
                var data = JSON.parse(xhr.responseText);
                if(data.status=="1"){
                    yisutui.getprize();
                }
                if(data.status=="2"){
                        yisutui.pwechatform(); 
                }
            },
             failure: function() {
                alert("网络异常！");
            }
        });
    }
    // 游戏抽奖接口 20150725 ggb
    yisutui.getprize = function() {
        isallshow = false;
        Ajax.request("/g/get_prize", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                score: gamescore
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                //获取结束页面相关图片设置
                if (parseInt(data.picset) == 1) { //有设置结束页面的相关图片
                    var ystbackover = data.itempic.ystbackover;
                    var ystexch = data.itempic.ystexch;
                    var ystguabg = data.itempic.ystguabg;
                } else { //没设置
                    var ystbackover = "ystbackover.png";
                    var ystexch = "ystexch.png";
                    var ystguabg = "ystguabg.png";
                }

                console.log("code----->" + data.code);

                if (parseInt(data.code) == 3) {
                    var yisutui_ = document.getElementById('lottery');

                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'lottery';
                        var prizetip = data.data.prizetip;
                        if (prizetip.length >= 15) { // 中奖提示字数限制
                            prizetip = prizetip.substr(0, 15);
                        }
                        yisutui__div.innerHTML = "<div class='lottrycontainer' id='lottrycontainer'><img src='" + domain + "/files/images/" + ystguabg + "' class='guabg'><div id='lottery-box'><img src='" + domain + "/files/images/" + data.data.prizepic + "' class='prize-img' id='prize-img'><p class='prize-text'>" + data.data.awardname + "</p><div class='prize-desc'>" + prizetip + "</div></div><div id='yst-gua-box' style='width:29.5rem;margin:0 auto;'><canvas id='yst-gua' style='position:absolute;border-radius: 1.2rem;margin-left: 0.1rem;'/></div><img src='" + domain + "/files/images/" + ystexch + "' class='yst-exchange' ontouchstart='yisutui.cashprize(" + data.data.level + ")'><img src='" + domain + "/files/images/" + ystbackover + "' class='yst-backover' ontouchstart='yisutui.backover()'></div>"
                        yisutui__css.innerHTML = ".lottrycontainer {position: fixed; top: 0px; left: 0px;height: 100%; width:100%; z-index: 9947483688;} .guabg{position: fixed;left:0;top: 0;width: 100%;height: 100%;} #lottery-box{position: fixed;left: 19.1%;top: 41.3%;width: 62.3%;height: 18%;} #guaguaka{width: 100%;height: 100%;border-radius:1.2rem;} .yst-exchange{width: 40%;position: fixed;left: 30%;top: 69%;} .yst-backover{width: 40%;position: fixed;left: 30%;top: 77%;} .prize-img{position: fixed;border-radius: 100%;margin-top: 6%;left: 24%;} .prize-text{position: fixed;width: 27.78%;text-align: center;font-weight: 700;margin-left: 27%;margin-top: 13%;font-family: Microsoft YaHei,Helvetica,Tahoma;font-size:1.4rem;}.prize-desc{width: 100%;margin: 0 auto;margin-top: 42%;font-size: 0.7rem;text-align: center;font-family: Microsoft YaHei,Helvetica,Tahoma;color:#12a5f8;}"

                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        var yisutui_ = document.getElementById('yisutui_');
                        // yisutui_.removeChild(yisutui_.childNodes[0]);

                        var Dw = document.documentElement.clientWidth;
                        var Dh = document.documentElement.clientHeight;
                        var prizeimg = document.getElementById('prize-img');
                        prizeimg.style.width = 0.2 * Dw + "px";
                        prizeimg.style.height = 0.2 * Dw + "px";
                        prizeimg.style.marginTop = (0.18 * Dh - 0.2 * Dw) / 2 + "px";
                        var width = document.documentElement.clientWidth * 0.623;
                        var height = document.documentElement.clientHeight * 0.18;
                        var guatop = document.documentElement.clientHeight * 0.413;

                        document.getElementById('yst-gua-box').style.width = width + "px";
                        document.getElementById('yst-gua-box').style.marginTop = guatop + "px";
                        gauguaka(width, height);
                        var gua = 1,
                            re = 2;

                        function gauguaka(width, height) {
                            var img = new Image();
                            var canvas = document.getElementById('yst-gua');
                            canvas.style.position = 'absolute';
                            var ctx;
                            var w = width,
                                h = height;
                            var offsetX = canvas.offsetLeft,
                                offsetY = canvas.offsetTop;
                            var mousedown = false;
                            // 处理刮刮卡面积
                            var flag = 0;
                            var opacityb = 0.5;
                            var backcolorb = "#aaa";
                            var numl = w * h;
                            var nump;
                            var opacitya;
                            var imgData;
                            var rgbabox = [];
                            // 确定canvas的区域
                            function layer(ctx) {
                                ctx.fillStyle = '#aaa';
                                ctx.fillRect(0, 0, w, h);
                            }

                            function eventDown(e) {
                                flag = 1; //标志按下                
                                e.preventDefault();
                                mousedown = true;
                            }

                            function eventUp(e) {
                                e.preventDefault();
                                mousedown = false;
                                flag = 0;
                                imgData = ctx.getImageData(0, 0, w, h);
                                for (var i = 0; i < imgData.data.length; i += 4) {
                                    var rval = imgData.data[i];
                                    var gval = imgData.data[i + 1];
                                    var bval = imgData.data[i + 2];
                                    var aval = imgData.data[i + 3];
                                    var rgbaval = rval + "-" + gval + "-" + bval + "-" + aval;
                                    rgbabox.push(rgbaval);
                                }
                                //end
                                for (var j = 0; j < rgbabox.length; j++) {
                                    rgbabox[j] = '#' + rgbToHex(rgbabox[j].split("-")[0], rgbabox[j].split("-")[1], rgbabox[j].split("-")[2]);
                                }
                                nump = countSubstr(rgbabox.join(","), backcolorb, true);
                                opacitya = (numl - nump) / numl;
                                if (opacitya > opacityb) {
                                    console.log("刮开了！");
                                    isallshow = true;
                                } else {
                                    console.log("还没有刮开了啦啦~~~");
                                    isallshow = false;
                                }
                            }

                            function rgbToHex(r, g, b) {
                                return ((r << 16) | (g << 8) | b).toString(16);
                            }

                            function countSubstr(str, substr, isIgnore) {
                                var count;
                                var reg = "";
                                if (isIgnore == true) {
                                    reg = "/" + substr + "/gi";
                                } else {
                                    reg = "/" + substr + "/g";
                                }
                                reg = eval(reg);
                                if (str.match(reg) == null) {
                                    count = 0;
                                } else {
                                    count = str.match(reg).length;
                                }
                                return count;
                            }

                            function eventMove(e) {
                                e.preventDefault();
                                if (mousedown && flag == 1) {
                                    if (e.changedTouches) {
                                        e = e.changedTouches[e.changedTouches.length - 1];
                                    }
                                    var x = (e.clientX + document.body.scrollLeft || e.pageX) - offsetX || 0,
                                        y = (e.clientY + document.body.scrollTop || e.pageY) - offsetY || 0;
                                    with(ctx) {
                                        beginPath()
                                        arc(x, y, 20, 0, Math.PI * 2);
                                        closePath();
                                        fill();
                                    }
                                }
                            }
                            canvas.width = w;
                            canvas.height = h;
                            ctx = canvas.getContext('2d');
                            ctx.fillStyle = 'b9b9b9';
                            ctx.fillRect(0, 0, w, h);
                            layer(ctx);
                            ctx.globalCompositeOperation = 'destination-out';
                            canvas.addEventListener('touchstart', eventDown);
                            canvas.addEventListener('touchend', eventUp);
                            canvas.addEventListener('touchmove', eventMove);
                            canvas.addEventListener('mousedown', eventDown);
                            canvas.addEventListener('mouseup', eventUp);
                            canvas.addEventListener('mousemove', eventMove);

                            (document.body.style);
                        }
                    }
                } else if (parseInt(data.code) == 1) {
                    alert(data.msg);
                } else if (parseInt(data.code) == 2) {
                    // alert(data.msg);
                    var yisutui_ = document.getElementById('lottery');

                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'lottery';
                        if (data.msg.length >= 26) { // 中奖提示字数限制
                            data.msg = data.msg.substr(0, 26);
                        }
                        yisutui__div.innerHTML = "<div class='lottrycontainer' id='lottrycontainer'><img src='" + domain + "/files/images/" + ystguabg + "' class='guabg'><div id='lottery-box'><p class='prize-text'>" + data.msg + "</p></div><div id='yst-gua-box' style='width:29.5rem;margin:0 auto;'><canvas id='yst-gua' style='position:absolute;border-radius: 1.2rem;margin-left: 0.1rem;z-index: 9947483688;'/></div><img src='" + domain + "/files/images/" + ystexch + "' class='yst-exchange' ontouchstart=alert('" + data.msg + "')><img src='" + domain + "/files/images/" + ystbackover + "' class='yst-backover' ontouchstart='yisutui.backover()'></div>"
                        yisutui__css.innerHTML = ".lottrycontainer {position: fixed; top: 0px; left: 0px;height: 100%; width:100%; z-index: 9947483688;} .guabg{position: fixed;left:0;top: 0;width: 100%;height: 100%;} #lottery-box{position: fixed;left: 19.1%;top: 41.3%;width: 62.3%;height: 18%;} #guaguaka{width: 100%;height: 100%;border-radius:1.2rem;} .yst-exchange{width: 40%;position: fixed;left: 30%;top: 69%;z-index: 9947483688;} .yst-backover{width: 40%;position: fixed;left: 30%;top: 77%;z-index: 9947483688;} .prize-img{position: fixed;border-radius: 100%;margin-top: 6%;left: 24%;} .prize-text{position: fixed;width: 62%;text-align: center;font-weight: 700;margin-left: 0px;margin-top: 13%;font-family: Microsoft YaHei,Helvetica,Tahoma;font-size:1.4rem;}.prize-desc{width: 100%;margin: 0 auto;margin-top: 42%;font-size: 0.7rem;text-align: center;font-family: Microsoft YaHei,Helvetica,Tahoma;color:#12a5f8;}"

                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        var yisutui_ = document.getElementById('yisutui_');
                        // yisutui_.removeChild(yisutui_.childNodes[0]);

                        var Dw = document.documentElement.clientWidth;
                        var Dh = document.documentElement.clientHeight;

                        var width = document.documentElement.clientWidth * 0.623;
                        var height = document.documentElement.clientHeight * 0.18;
                        var guatop = document.documentElement.clientHeight * 0.413;

                        document.getElementById('yst-gua-box').style.width = width + "px";
                        document.getElementById('yst-gua-box').style.marginTop = guatop + "px";
                        gauguaka(width, height);
                        var gua = 1,
                            re = 2;

                        function gauguaka(width, height) {
                            var img = new Image();
                            var canvas = document.getElementById('yst-gua');
                            canvas.style.position = 'absolute';
                            var ctx;
                            var w = width,
                                h = height;
                            var offsetX = canvas.offsetLeft,
                                offsetY = canvas.offsetTop;
                            var mousedown = false;
                            // 处理刮刮卡面积
                            var flag = 0;
                            var opacityb = 0.5;
                            var backcolorb = "#aaa";
                            var numl = w * h;
                            var nump;
                            var opacitya;
                            var imgData;
                            var rgbabox = [];
                            // 确定canvas的区域
                            function layer(ctx) {
                                ctx.fillStyle = '#aaa';
                                ctx.fillRect(0, 0, w, h);
                            }

                            function eventDown(e) {
                                flag = 1; //标志按下                
                                e.preventDefault();
                                mousedown = true;
                            }

                            function eventUp(e) {
                                e.preventDefault();
                                mousedown = false;
                                flag = 0;
                                imgData = ctx.getImageData(0, 0, w, h);
                                for (var i = 0; i < imgData.data.length; i += 4) {
                                    var rval = imgData.data[i];
                                    var gval = imgData.data[i + 1];
                                    var bval = imgData.data[i + 2];
                                    var aval = imgData.data[i + 3];
                                    var rgbaval = rval + "-" + gval + "-" + bval + "-" + aval;
                                    rgbabox.push(rgbaval);
                                }
                                //end
                                for (var j = 0; j < rgbabox.length; j++) {
                                    rgbabox[j] = '#' + rgbToHex(rgbabox[j].split("-")[0], rgbabox[j].split("-")[1], rgbabox[j].split("-")[2]);
                                }
                                nump = countSubstr(rgbabox.join(","), backcolorb, true);
                                opacitya = (numl - nump) / numl;
                                if (opacitya > opacityb) {
                                    console.log("刮开了！");
                                    isallshow = true;
                                } else {
                                    console.log("还没有刮开了啦啦~~~");
                                    isallshow = false;
                                }
                            }

                            function rgbToHex(r, g, b) {
                                return ((r << 16) | (g << 8) | b).toString(16);
                            }

                            function countSubstr(str, substr, isIgnore) {
                                var count;
                                var reg = "";
                                if (isIgnore == true) {
                                    reg = "/" + substr + "/gi";
                                } else {
                                    reg = "/" + substr + "/g";
                                }
                                reg = eval(reg);
                                if (str.match(reg) == null) {
                                    count = 0;
                                } else {
                                    count = str.match(reg).length;
                                }
                                return count;
                            }

                            function eventMove(e) {
                                e.preventDefault();
                                if (mousedown && flag == 1) {
                                    if (e.changedTouches) {
                                        e = e.changedTouches[e.changedTouches.length - 1];
                                    }
                                    var x = (e.clientX + document.body.scrollLeft || e.pageX) - offsetX || 0,
                                        y = (e.clientY + document.body.scrollTop || e.pageY) - offsetY || 0;
                                    with(ctx) {
                                        beginPath()
                                        arc(x, y, 20, 0, Math.PI * 2);
                                        closePath();
                                        fill();
                                    }
                                }
                            }
                            canvas.width = w;
                            canvas.height = h;
                            ctx = canvas.getContext('2d');
                            ctx.fillStyle = 'b9b9b9';
                            ctx.fillRect(0, 0, w, h);
                            layer(ctx);
                            ctx.globalCompositeOperation = 'destination-out';
                            canvas.addEventListener('touchstart', eventDown);
                            canvas.addEventListener('touchend', eventUp);
                            canvas.addEventListener('touchmove', eventMove);
                            canvas.addEventListener('mousedown', eventDown);
                            canvas.addEventListener('mouseup', eventUp);
                            canvas.addEventListener('mousemove', eventMove);

                            (document.body.style);
                        }
                    }
                }
            },
            failure: function() {
                alert("网络异常！");
            }
        });
        var gamegetprize = document.getElementById('gamegetprize');
        if (gamegetprize.removeEventListener) { // // 所有浏览器，除了 IE 8 及更早IE版本
            gamegetprize.removeEventListener("touchstart", yisutui.ptypeform, false);
        } else if (gamegetprize.detachEvent) { // IE 8 及更早IE版本
            gamegetprize.detachEvent("touchstart", yisutui.ptypeform);
        }
        //添加监听事件
        gamegetprize.addEventListener("touchstart", yisutui.moreclicktip, false);
    };

    //抽奖公众号中接口 20160317 syq
    yisutui.pwechatform = function() {
        var isbarrage=document.getElementById('yst-barrage-mask');
        if(isbarrage){
            isbarrage.style.display="none";
        }
        var yisutui_start = document.getElementById('redcommend');
        if (!yisutui_start) {
            Ajax.request('/g/create_prizetoken', {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: { itemid: itemid, score: gamescore },
                success: function(xhr) {

                    var data = JSON.parse(xhr.responseText);
                    if(data.status==2){
                        var tip=data.tip;
                        if(tip == ""){
                            tip="得分不足";
                        }
                        alert(tip);
                        return;
                    }
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'redcommend';
                    yisutui__div.innerHTML = "<div class='yst-get-passwordred'><div class='yst-passwordred-top'><div  id='yst-passwordred-text' class='yst-passwordred-text'>" + data.token + "</div></div><div class='yst-passwordred-qr'><img src='" + data.qrcodeurl + "'></div><div class='yst-passwordred-bottom'><p>领取说明:</p><div class='yst-receive-con'>" + data.gettip + "</div></div><img src='" + domain + "/files/images/tokenback.png' class='redcom-back' ontouchstart='yisutui.rwechatclose()'></div>";
                    yisutui__css.innerHTML = "html{font-size:62.5%;}a, p, span, ul, ol, li, td {-webkit-tap-highlight-color: rgba(0, 0, 0, 0);padding: 0;margin: 0;list-style-type: none;text-decoration: none;}body{background: #fff;margin: 0;}.yst-get-passwordred{width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:99999;background-color:#fff}.yst-passwordred-top{width: 100%;height: 30%;text-align: center;background:url(/API/img/wordbg.png);background-size: 100% 100%;position:relative}.yst-passwordred-text{background-color:#fff;line-height:30px;width: 41%;height: 30px;outline: none;border: 0;border-radius: 12px;font-size: 1.4rem;text-align: center;padding: 0.5% 3% 0;color: #666;display: inline-block;font-weight: bold;position:absolute;top:41%;left:25%}.yst-passwordred-btn{border: 0;height: 100%;width: 25%;border-radius: 10px;background:yellow;color:red;margin-left:1%;outline:none;}.yst-passwordred-qr{text-align:center;margin-top:8%;height:30%;padding-bottom:8%;width:70%;margin-left:15%;border-bottom:1px dashed #fe514a;}.yst-passwordred-qr img{height:100%;}.yst-passwordred-bottom{margin-top:8%;width:100%;height:15%;}.yst-passwordred-bottom p{margin-left:10%; width:80%; font-size:1.6rem;color:#000;font-weight: bold;}.redcom-back{width: 40%;margin: 0% 30% 0px;position:fixed;bottom:5%}.yst-receive-con{width: 80%;margin-left: 10%;margin-top: 5px;font-size: 1.3rem;text-indent:2em;}";
                    var first = document.body.firstChild;
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            });
        }else{
           // var gamegetprize=document.getElementById('gamegetprize');
           //  gamegetprize.addEventListener("touchstart", yisutui.moreclicktip, false); 
           alert("亲~每次游戏结束后，只能领取一次口令");


        }

        
    }

    //兑奖页面返回
    yisutui.backover = function() {
        var lottery = document.getElementById('lottery');
        // lottery.removeChild(lottery.childNodes[0]);
        lottery.style.display = "none";
    }

    //中奖后兑奖接口 20150725 ggb
    yisutui.cashprize = function(level) {
        if (!isallshow) {
            alert("还没有刮开宝贝呀！要无情的抛弃吗？");
            return;
        }
        var mstyle = 0;
        Ajax.request("/g/get_form", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                mstyle: mstyle
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    var yisutui_start = document.getElementById('prizeform');
                    if (!yisutui_start) {
                        var yisutui_start_div = document.createElement('div');
                        var yisutui_start_css = document.createElement('style');
                        yisutui_start_div.id = 'prizeform';

                        yisutui_start_div.innerHTML = "<div class='cashcontainer' id='cashcontainer'><div class='yst_enroll_bg'><img src='" + domain + "/files/images/" + cashprizetopbg + "'></div><div class='yst_enroll_form'><div class='yst_enroll_explain'><h3>兑奖说明</h3><p>" + data.tip + "</p></div><div class='yst_enroll_contact' id='yst_enroll_contact'><p>请留下您的联系信息，我们的工作人员会联系您</p></div></div></div>";
                        yisutui_start_css.innerHTML = "#prizeform{background:#e6303f;position:fixed;width: 100%;height:100%;z-index:9999;overflow:hidden;}.cashcontainer {position:relative;width: 100%;height: 100%;overflow-y:scroll;}.yst_enroll_bg{width: 100%;position:relative;top: 0; left: 0;} .yst_enroll_bg img{width: 100%;}.yst_enroll_form{background-image:url('" + domain + "/files/images/" + cashprizebg + "');background-size:cover;width: 100%; color: #FFF;padding-top:5%;margin-top:-2%;padding-bottom:10%;}.yst_enroll_explain{ width: 80%; border:2px solid #f8c8cc; border-radius: 20px;  margin:5% auto 0;} .yst_enroll_explain h3{text-align:center; margin: 2%;} .yst_enroll_explain p{text-indent: 2em;width: 90%;margin: 0 auto 3%;} .yst_enroll_contact{height: 74%; width: 80%; border:2px solid #f8c8cc; margin:7% auto 0; border-radius: 20px;} .yst_enroll_contact p{width: 78%; margin-left: 11% ;margin-bottom: 5%;margin-top:5%;} .yst_enroll_number{width: 68%; margin-left: 11%; padding: 2% 5%;border-radius: 15px;border:0;margin-bottom: 7%;outline: none;} .yst_enroll_submit{width: 78%; margin-left: 11%;border-radius:22px;border:0;margin-bottom: 8%;font-size:1rem; color: #FFF; font-weight: bold; margin-top: 1%;outline:none;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui_start_div, first);
                        document.head.appendChild(yisutui_start_css);
                        var formone = "<div>";
                        for (var o in data.data) {
                            var i = parseInt(o, 10) + 1;
                            var str = '请输入您的' + data['data'][o]['name'];
                            formone = formone + "<input type='text' class='yst_enroll_number' id='cashforminput" + i + "' placeholder=" + str + " />";
                        }
                        formone = formone + "<img src='" + domain + "/files/images/" + cashprizesubmit + "' class='yst_enroll_submit'  value='提交' id='formsubmit' formnum='" + data.data.length + "' ontouchstart='yisutui.formsubmit(" + mstyle + "," + level + ")'/><img src='" + domain + "/files/images/back_btn.png' class='yst_enroll_submit' ontouchstart='yisutui.closeForm()'></div>";
                        var cashform = document.getElementById('yst_enroll_contact');
                        var cashform = document.getElementById('yst_enroll_contact');
                        yisutui.append(cashform, formone);
                        // var lottery=document.getElementById('lottery');
                        var lottery = document.body;
                        lottery.removeChild(lottery.childNodes[1]);
                    }
                }
                if(data.code == "2"){
                    alert('表单出错！');
                } 
                if(data.code == "3"){
                   alert(data.msg); 
                } 
                if (data.code == "4") {
                    var yisutui_start = document.getElementById('prizeform');
                    if (!yisutui_start) {
                        var yisutui_start_div = document.createElement('div');
                        var yisutui_start_css = document.createElement('style');
                        yisutui_start_div.id = 'prizeform';

                        yisutui_start_div.innerHTML = "<div class='cashcontainer' id='cashcontainer'><div class='yst_enroll_bg'><img src='" + domain + "/files/images/" + cashprizetopbg + "'></div><div class='yst_enroll_form'><div class='yst_enroll_explain'><h3>兑奖说明</h3><p>" + data.tip + "</p></div><div class='yst_enroll_contact' id='yst_enroll_contact'><p>请留下您的联系信息，我们的工作人员会联系您</p></div></div></div>";
                        yisutui_start_css.innerHTML = "#prizeform{background:#e6303f;position:fixed;width: 100%;height:100%;z-index:9999;overflow:hidden;}.cashcontainer {position:relative;width: 100%;height: 100%;overflow-y:scroll;}.yst_enroll_bg{width: 100%;position:relative;top: 0; left: 0;} .yst_enroll_bg img{width: 100%;}.yst_enroll_form{background-image:url('" + domain + "/files/images/" + cashprizebg + "');background-size:cover;width: 100%; color: #FFF;padding-top:5%;margin-top:-2%;padding-bottom:10%;}.yst_enroll_explain{ width: 80%; border:2px solid #f8c8cc; border-radius: 20px;  margin:5% auto 0;} .yst_enroll_explain h3{text-align:center; margin: 2%;} .yst_enroll_explain p{text-indent: 2em;width: 90%;margin: 0 auto 3%;} .yst_enroll_contact{height: 74%; width: 80%; border:2px solid #f8c8cc; margin:7% auto 0; border-radius: 20px;} .yst_enroll_contact p{width: 78%; margin-left: 11% ;margin-bottom: 5%;margin-top:5%;} .yst_enroll_number{width: 68%; margin-left: 11%; padding: 2% 5%;border-radius: 15px;border:0;margin-bottom: 7%;outline: none;} .yst_enroll_submit{width: 78%; margin-left: 11%;border-radius:22px;border:0;margin-bottom: 8%;font-size:1rem; color: #FFF; font-weight: bold; margin-top: 1%;outline:none;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui_start_div, first);
                        document.head.appendChild(yisutui_start_css);
                        var formone = "<div>";
                        for (var o in data.data) {
                            var i = parseInt(o, 10) + 1;
                            var strname=data['pdata']['form'+i];
                                if(strname==null){
                                    strname="";
                                }
                            var str = '请输入您的' + data['data'][o]['name'];
                            formone = formone + "<input type='text' value='"+strname+"' class='yst_enroll_number' id='cashforminput" + i + "' placeholder=" + str + " />";
                        }
                        formone = formone + "<img src='" + domain + "/files/images/" + cashprizesubmit + "' class='yst_enroll_submit'  value='提交' id='formsubmit' formnum='" + data.data.length + "' ontouchstart='yisutui.pformsubmit(" + mstyle + "," + level + ")'/><img src='" + domain + "/files/images/back_btn.png' class='yst_enroll_submit' ontouchstart='yisutui.closeForm()'></div>";
                        var cashform = document.getElementById('yst_enroll_contact');
                        var cashform = document.getElementById('yst_enroll_contact');
                        yisutui.append(cashform, formone);
                        // var lottery=document.getElementById('lottery');
                        var lottery = document.body;
                        lottery.removeChild(lottery.childNodes[1]);
                    }
                }
                
            },
            failure: function() {
                alert("网络异常！");
            }
        });
    }; 
    //有数据提交抽奖表单接口 20160317 syq
    var isreceive=true;
    yisutui.pformsubmit = function(formtype, level) {
        if(!isreceive){
            return false;
        }
        isreceive=false;
        var mstyle = formtype;
        var formnum = document.getElementById('formsubmit').getAttribute('formnum');
        var mform = [];
        for (var j = 0; j < formnum; j++) {
            var i = j + 1;
            var value = document.getElementById("cashforminput" + i).value;
            mform[j] = value;
        }
        var isput = false;
        for (var i = 0; i < formnum; i++) {
            if (mform[i] == "" || mform[i] == null) {
                isput = false;
                break;
            } else {
                isput = true;
            }
        }
        
        if (isput) {
            Ajax.request("/g/formadd", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    mstyle: mstyle,
                    level: level,
                    mform: mform
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (data.code == "1") {
                        // view("修改成功！");    
                        alert("保存成功");
                        // var prizeform=document.getElementById('prizeform');
                        var prizeform = document.body;
                        prizeform.removeChild(prizeform.childNodes[0]);
                        isreceive=true;
                    } else {
                        isreceive=true;
                        alert(data.msg);
                    }
                },
                failure: function() {
                    isreceive=true;
                    alert("网络异常！");
                }
            });
        } else {
            isreceive=true;
            alert("请填写您的联系信息！");
        }
    };
    //提交表单接口 20150725 ggb
    var isreceive=true;
    yisutui.formsubmit = function(formtype, level) {
        if(!isreceive){
            return false;
        }
        isreceive=false;
        var mstyle = formtype;
        var formnum = document.getElementById('formsubmit').getAttribute('formnum');
        var mform = [];
        for (var j = 0; j < formnum; j++) {
            var i = j + 1;
            var value = document.getElementById("cashforminput" + i).value;
            mform[j] = value;
        }
        var isput = false;
        for (var i = 0; i < formnum; i++) {
            if (mform[i] == "" || mform[i] == null) {
                isput = false;
                break;
            } else {
                isput = true;
            }
        }
        if (isput) {
            Ajax.request("/g/formadd", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    mstyle: mstyle,
                    level: level,
                    mform: mform
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (data.code == "1") {
                        // view("修改成功！");    
                        alert("保存成功");
                        // var prizeform=document.getElementById('prizeform');
                        var prizeform = document.body;
                        prizeform.removeChild(prizeform.childNodes[0]);
                        isreceive=true;
                    } else {
                        isreceive=true;
                        alert(data.msg);
                    }
                },
                failure: function() {
                    isreceive=true;
                    alert("网络异常！");
                }
            });
        } else {
            isreceive=true;
            alert("请填写您的联系信息！");
        }
    };
    //有数据提交表单接口 20150725 ggb
    var isreceive=true;
    yisutui.mformsubmit = function(formtype, level) {
        if(!isreceive){
            return false;
        }
        isreceive=false;
        var mstyle = formtype;
        var formnum = document.getElementById('formsubmit').getAttribute('formnum');
        var mform = [];
        for (var j = 0; j < formnum; j++) {
            var i = j + 1;
            var value = document.getElementById("cashforminput" + i).value;
            mform[j] = value;
        }
        var isput = false;
        for (var i = 0; i < formnum; i++) {
            if (mform[i] == "" || mform[i] == null) {
                isput = false;
                break;
            } else {
                isput = true;
            }
        }
        if (isput) {
            Ajax.request("/g/editform", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    mstyle: mstyle,
                    level: level,
                    mform: mform
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (data.code == "1") {
                        // view("修改成功！");    
                        alert("保存成功");
                        // var prizeform=document.getElementById('prizeform');
                        var prizeform = document.body;
                        prizeform.removeChild(prizeform.childNodes[0]);
                        isreceive=true;
                    } else {
                        isreceive=true;
                        alert(data.msg);
                    }
                },
                failure: function() {
                    isreceive=true;
                    alert("网络异常！");
                }
            });
        } else {
            isreceive=true;
            alert("请填写您的联系信息！");
        }
    };

    //营销方式为表单接口 20150804 ggb
    yisutui.mform = function() {
        var mstyle = 1;
        Ajax.request("/g/get_form", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                mstyle: mstyle
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {

                    var yisutui_ = document.getElementById('prizeform');

                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'prizeform';
                        yisutui__div.innerHTML = "<div class='outbg'><div class='cashcontainer' id='cashcontainer'><div class='yst_enroll_bg'><img src='" + domain + "/files/images/" + enrolltopbg + "'></div><div class='yst_enroll_form'><div class='yst_enroll_explain'><h3>说明</h3><p>" + data.tip + "</p></div><div class='yst_enroll_contact' id='yst_enroll_contact'><p>请留下您的联系信息，我们的工作人员会联系您</p></div></div></div>";
                        yisutui__css.innerHTML = ".cashcontainer{position: relative; top:0px; left:0px; width: 100%; z-index: 994748882; height: 100%;background-color: #e6303f;overflow:auto;} .yst_enroll_bg{width: 100%; height: 22%; position: relative; top: 0; left: 0;} .yst_enroll_bg img{width: 100%; height: 100%;} .yst_enroll_form{background-image:url('" + domain + "/files/images/" + enrollbg + "');background-size:cover;width: 100%; padding-top:5%;margin-top:-2%;padding-bottom:10%; color: #FFF;} .yst_enroll_explain{height: 20%; width: 80%; border:0.2rem solid #f8c8cc; border-radius: 2rem;  margin: auto; font-size: 1.2rem;} .yst_enroll_explain h3{text-align:center; margin: 0;} .yst_enroll_explain p{text-indent: 2em;width: 90%;margin: 0 auto 3%;} .yst_enroll_contact{ width: 80%; border:0.2rem solid #f8c8cc; margin:7% auto 0; border-radius: 2rem; } .yst_enroll_contact p{width: 78%; margin-left: 11% ;margin-bottom: 5%;margin-top:5%;} .yst_enroll_number{width: 68%; margin-left: 11%; padding: 2% 5%;border-radius: 1.5rem;border:0;margin-bottom: 7%;outline: none;} .yst_enroll_submit{width: 78%; margin-left: 11%; border-radius: 2.2rem;border:0;margin-bottom:8%;  font-size: 1rem; color: #FFF; font-weight: bold;outline:none;} .outbg{position:fixed;width:100%;height:100%; background-color: #e6303f;z-index:994748882;overflow: hidden;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        var formone = "<div>";
                        for (var o in data.data) {
                            var i = parseInt(o, 10) + 1;
                            var str = '请输入您的' + data['data'][o]['name'];
                            formone = formone + "<input type='text' class='yst_enroll_number' id='cashforminput" + i + "' placeholder=" + str + " />";
                        }
                        formone = formone + "<img src='" + domain + "/files/images/" + enrollsubmit + "' class='yst_enroll_submit'  value='提交' id='formsubmit' formnum='" + data.data.length + "' ontouchstart='yisutui.formsubmit(" + mstyle + ",0)'/><img src='" + domain + "/files/images/back_btn.png' class='yst_enroll_submit' ontouchstart='yisutui.closeForm()'></div>";
                        var cashform = document.getElementById('yst_enroll_contact');
                        yisutui.append(cashform, formone);
                        // var yisutui_=document.getElementById('yisutui_');
                        // yisutui_.removeChild(yisutui_.childNodes[0]);
                    }
                } 
                if(data.code == "2"){
                    alert('表单出错！');
                } 
                if(data.code == "3"){
                   alert(data.msg); 
                } 
                if (data.code == "4") {

                    var yisutui_ = document.getElementById('prizeform');

                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'prizeform';
                        yisutui__div.innerHTML = "<div class='outbg'><div class='cashcontainer' id='cashcontainer'><div class='yst_enroll_bg'><img src='" + domain + "/files/images/" + enrolltopbg + "'></div><div class='yst_enroll_form'><div class='yst_enroll_explain'><h3>说明</h3><p>" + data.tip + "</p></div><div class='yst_enroll_contact' id='yst_enroll_contact'><p>请留下您的联系信息，我们的工作人员会联系您</p></div></div></div>";
                        yisutui__css.innerHTML = ".cashcontainer{position: relative; top:0px; left:0px; width: 100%; z-index: 994748882; height: 100%;background-color: #e6303f;overflow:auto;} .yst_enroll_bg{width: 100%; height: 22%; position: relative; top: 0; left: 0;} .yst_enroll_bg img{width: 100%; height: 100%;} .yst_enroll_form{background-image:url('" + domain + "/files/images/" + enrollbg + "');background-size:cover;width: 100%; padding-top:5%;margin-top:-2%;padding-bottom:10%; color: #FFF;} .yst_enroll_explain{height: 20%; width: 80%; border:0.2rem solid #f8c8cc; border-radius: 2rem;  margin: auto; font-size: 1.2rem;} .yst_enroll_explain h3{text-align:center; margin: 0;} .yst_enroll_explain p{text-indent: 2em;width: 90%;margin: 0 auto 3%;} .yst_enroll_contact{ width: 80%; border:0.2rem solid #f8c8cc; margin:7% auto 0; border-radius: 2rem; } .yst_enroll_contact p{width: 78%; margin-left: 11% ;margin-bottom: 5%;margin-top:5%;} .yst_enroll_number{width: 68%; margin-left: 11%; padding: 2% 5%;border-radius: 1.5rem;border:0;margin-bottom: 7%;outline: none;} .yst_enroll_submit{width: 78%; margin-left: 11%; border-radius: 2.2rem;border:0;margin-bottom:8%;  font-size: 1rem; color: #FFF; font-weight: bold;outline:none;} .outbg{position:fixed;width:100%;height:100%; background-color: #e6303f;z-index:994748882;overflow: hidden;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        var formone = "<div>";
                        for (var o in data.data) {
                            var i = parseInt(o, 10) + 1;
                            var strname=data['pdata']['form'+i];
                                if(strname==null){
                                    strname="";
                                }
                            var str = '请输入您的' + data['data'][o]['name'];
                            formone = formone + "<input type='text' class='yst_enroll_number' value='"+strname+"' id='cashforminput" + i + "' placeholder=" + str + " />";
                        }
                        formone = formone + "<img src='" + domain + "/files/images/" + enrollsubmit + "' class='yst_enroll_submit'  value='提交' id='formsubmit' formnum='" + data.data.length + "' ontouchstart='yisutui.mformsubmit(" + mstyle + ",0)'/><img src='" + domain + "/files/images/back_btn.png' class='yst_enroll_submit' ontouchstart='yisutui.closeForm()'></div>";
                        var cashform = document.getElementById('yst_enroll_contact');
                        yisutui.append(cashform, formone);
                        // var yisutui_=document.getElementById('yisutui_');
                        // yisutui_.removeChild(yisutui_.childNodes[0]);
                    }
                } 
            },
            failure: function() {
                alert("网络异常！");
            }
        });
    };
    //排行榜判断在游戏中还是公众号领奖
    yisutui.typeform=function(){
        Ajax.request("/g/drawtype",{
            async:true,
            method:"POST",
            encode:"UTF-8",
            data:{
                itemid:itemid
            },
            success:function(xhr){
                var data = JSON.parse(xhr.responseText);
                if(data.status=="1"){
                    yisutui.rgameform();
                }
                if(data.status=="2"){
                    yisutui.rwechatform();
                }
            },
             failure: function() {
                alert("网络异常！");
            }
        });
    }
    //营销方式为排行榜游戏中接口 20160315 syq
    yisutui.rgameform = function() {
        var mstyle = 2;
        Ajax.request("/g/get_form", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                mstyle: mstyle
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {

                    var yisutui_ = document.getElementById('prizeform');

                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'prizeform';
                        yisutui__div.innerHTML = "<div class='outbg'><div class='cashcontainer' id='cashcontainer'><div class='yst_enroll_bg'><img src='" + domain + "/files/images/" + enrolltopbg + "'></div><div class='yst_enroll_form'><div class='yst_enroll_explain'><h3>说明</h3><p>" + data.tip + "</p></div><div class='yst_enroll_contact' id='yst_enroll_contact'><p>请留下您的联系信息，我们的工作人员会联系您</p></div></div></div>";
                        yisutui__css.innerHTML = ".cashcontainer{position: relative; top:0px; left:0px; width: 100%; z-index: 994748882; height: 100%;background-color: #e6303f;overflow:auto;} .yst_enroll_bg{width: 100%; height: 22%; position: relative; top: 0; left: 0;} .yst_enroll_bg img{width: 100%; height: 100%;} .yst_enroll_form{background-image:url('" + domain + "/files/images/" + enrollbg + "');background-size:cover;width: 100%; padding-top:5%;margin-top:-2%;padding-bottom:10%; color: #FFF;} .yst_enroll_explain{height: 20%; width: 80%; border:0.2rem solid #f8c8cc; border-radius: 2rem;  margin: auto; font-size: 1.2rem;} .yst_enroll_explain h3{text-align:center; margin: 0;} .yst_enroll_explain p{text-indent: 2em;width: 90%;margin: 0 auto 3%;} .yst_enroll_contact{ width: 80%; border:0.2rem solid #f8c8cc; margin:7% auto 0; border-radius: 2rem; } .yst_enroll_contact p{width: 78%; margin-left: 11% ;margin-bottom: 5%;margin-top:5%;} .yst_enroll_number{width: 68%; margin-left: 11%; padding: 2% 5%;border-radius: 1.5rem;border:0;margin-bottom: 7%;outline: none;} .yst_enroll_submit{width: 78%; margin-left: 11%; border-radius: 2.2rem;border:0;margin-bottom:8%;  font-size: 1rem; color: #FFF; font-weight: bold;outline:none;} .outbg{position:fixed;width:100%;height:100%; background-color: #e6303f;z-index:994748882;overflow: hidden;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        var formone = "<div>";
                        for (var o in data.data) {
                            var i = parseInt(o, 10) + 1;
                            
                            var str = '请输入您的' + data['data'][o]['name'];
                            formone = formone + "<input type='text' class='yst_enroll_number'  id='cashforminput" + i + "' placeholder=" + str + " />";
                        }
                        formone = formone + "<img src='" + domain + "/files/images/" + enrollsubmit + "' class='yst_enroll_submit'  value='提交' id='formsubmit' formnum='" + data.data.length + "' ontouchstart='yisutui.formsubmit(" + mstyle + ",0)'/><img src='" + domain + "/files/images/back_btn.png' class='yst_enroll_submit' ontouchstart='yisutui.closeForm()'></div>";
                        var cashform = document.getElementById('yst_enroll_contact');
                        yisutui.append(cashform, formone);
                        // var yisutui_=document.getElementById('yisutui_');
                        // yisutui_.removeChild(yisutui_.childNodes[0]);
                    }
                } 
                if(data.code == "2"){
                    
                    alert('表单出错！');
                } 
                if(data.code == "3"){
                   alert(data.msg); 
                } 
                if(data.code == "4"){
                   var yisutui_ = document.getElementById('prizeform');

                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'prizeform';
                        yisutui__div.innerHTML = "<div class='outbg'><div class='cashcontainer' id='cashcontainer'><div class='yst_enroll_bg'><img src='" + domain + "/files/images/" + enrolltopbg + "'></div><div class='yst_enroll_form'><div class='yst_enroll_explain'><h3>说明</h3><p>" + data.tip + "</p></div><div class='yst_enroll_contact' id='yst_enroll_contact'><p>请留下您的联系信息，我们的工作人员会联系您</p></div></div></div>";
                        yisutui__css.innerHTML = ".cashcontainer{position: relative; top:0px; left:0px; width: 100%; z-index: 994748882; height: 100%;background-color: #e6303f;overflow:auto;} .yst_enroll_bg{width: 100%; height: 22%; position: relative; top: 0; left: 0;} .yst_enroll_bg img{width: 100%; height: 100%;} .yst_enroll_form{background-image:url('" + domain + "/files/images/" + enrollbg + "');background-size:cover;width: 100%; padding-top:5%;margin-top:-2%;padding-bottom:10%; color: #FFF;} .yst_enroll_explain{height: 20%; width: 80%; border:0.2rem solid #f8c8cc; border-radius: 2rem;  margin: auto; font-size: 1.2rem;} .yst_enroll_explain h3{text-align:center; margin: 0;} .yst_enroll_explain p{text-indent: 2em;width: 90%;margin: 0 auto 3%;} .yst_enroll_contact{ width: 80%; border:0.2rem solid #f8c8cc; margin:7% auto 0; border-radius: 2rem; } .yst_enroll_contact p{width: 78%; margin-left: 11% ;margin-bottom: 5%;margin-top:5%;} .yst_enroll_number{width: 68%; margin-left: 11%; padding: 2% 5%;border-radius: 1.5rem;border:0;margin-bottom: 7%;outline: none;} .yst_enroll_submit{width: 78%; margin-left: 11%; border-radius: 2.2rem;border:0;margin-bottom:8%;  font-size: 1rem; color: #FFF; font-weight: bold;outline:none;} .outbg{position:fixed;width:100%;height:100%; background-color: #e6303f;z-index:994748882;overflow: hidden;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                        var formone = "<div>";
                        for (var o in data.data) {

                            var i = parseInt(o, 10) + 1;
                            var strname=data['pdata']['form'+i];
                            if(strname==null){
                                strname="";
                            }
                            var str = '请输入您的' + data['data'][o]['name'];
                            formone = formone + "<input type='text' value='"+strname+"' class='yst_enroll_number' id='cashforminput" + i + "' placeholder=" + str + " />";
                        }

                        formone = formone + "<img src='" + domain + "/files/images/" + enrollsubmit + "' class='yst_enroll_submit'  value='提交' id='formsubmit' formnum='" + data.data.length + "' ontouchstart='yisutui.rformsubmit(" + mstyle + ",0)'/><img src='" + domain + "/files/images/back_btn.png' class='yst_enroll_submit' ontouchstart='yisutui.closeForm()'></div>";
                        var cashform = document.getElementById('yst_enroll_contact');
                        yisutui.append(cashform, formone);
                        // var yisutui_=document.getElementById('yisutui_');
                        // yisutui_.removeChild(yisutui_.childNodes[0]);
                    } 
                } 

            },
            failure: function() {
                alert("网络异常！");
            }
        });
    };
    //提交有数据排行榜表单接口 20160316 syq
    var isreceive=true;
    yisutui.rformsubmit = function(formtype, level) {
        if(!isreceive){
            return false;
        }
        isreceive=false;
        var mstyle = formtype;
        var formnum = document.getElementById('formsubmit').getAttribute('formnum');
        var mform = [];
        for (var j = 0; j < formnum; j++) {
            var i = j + 1;
            var value = document.getElementById("cashforminput" + i).value;
            mform[j] = value;
        }
        var isput = false;
        for (var i = 0; i < formnum; i++) {
            if (mform[i] == "" || mform[i] == null) {
                isput = false;
                break;
            } else {
                isput = true;
            }
        }
        if (isput) {
            Ajax.request("/g/editform", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    mstyle: mstyle,
                    level: level,
                    mform: mform
                },
                success: function(xhr) {
                    console.log(mform);
                    var data = JSON.parse(xhr.responseText);
                    if (data.code == "1") {
                        // view("修改成功！");    
                        alert("保存成功");
                        // var prizeform=document.getElementById('prizeform');
                        var prizeform = document.body;
                        prizeform.removeChild(prizeform.childNodes[0]);
                        isreceive=true;
                    } else {
                        isreceive=true;
                        alert(data.msg);
                    }
                },
                failure: function() {
                    isreceive=true;
                    alert("网络异常！");
                }
            });
        } else {
            isreceive=true;
            alert("请填写您的联系信息！");
        }
    };
    //营销方式为排行榜公众号中接口 20160315 syq
    yisutui.rwechatform = function() {
        var isbarrage=document.getElementById('yst-barrage-mask');
        if(isbarrage){
            isbarrage.style.display="none";
        }
        var yisutui_start = document.getElementById('redcommend');
        if (!yisutui_start) {
            Ajax.request('/g/create_ranktoken', {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: { itemid: itemid, score: gamescore },
                success: function(xhr) {

                    var data = JSON.parse(xhr.responseText);
                    if(data.status==2){
                        var tip=data.tip;
                        if(tip == ""){
                            tip="得分不足";
                        }
                        alert(tip);
                        return;
                    }
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'redcommend';
                    yisutui__div.innerHTML = "<div class='yst-get-passwordred'><div class='yst-passwordred-top'><div  id='yst-passwordred-text' class='yst-passwordred-text'>" + data.token + "</div></div><div class='yst-passwordred-qr'><img src='" + data.qrcodeurl + "'></div><div class='yst-passwordred-bottom'><p>领取说明:</p><div class='yst-receive-con'>" + data.gettip + "</div></div><img src='" + domain + "/files/images/tokenback.png' class='redcom-back' ontouchstart='yisutui.rwechatclose()'></div>";
                    yisutui__css.innerHTML = "html{font-size:62.5%;}a, p, span, ul, ol, li, td {-webkit-tap-highlight-color: rgba(0, 0, 0, 0);padding: 0;margin: 0;list-style-type: none;text-decoration: none;}body{background: #fff;margin: 0;}.yst-get-passwordred{width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:99999;background-color:#fff}.yst-passwordred-top{width: 100%;height: 30%;text-align: center;background:url(/API/img/wordbg.png);background-size: 100% 100%;position:relative}.yst-passwordred-text{background-color:#fff;line-height:30px;width: 41%;height: 30px;outline: none;border: 0;border-radius: 12px;font-size: 1.4rem;text-align: center;padding: 0.5% 3% 0;color: #666;display: inline-block;font-weight: bold;position:absolute;top:41%;left:25%}.yst-passwordred-btn{border: 0;height: 100%;width: 25%;border-radius: 10px;background:yellow;color:red;margin-left:1%;outline:none;}.yst-passwordred-qr{text-align:center;margin-top:8%;height:30%;padding-bottom:8%;width:70%;margin-left:15%;border-bottom:1px dashed #fe514a;}.yst-passwordred-qr img{height:100%;}.yst-passwordred-bottom{margin-top:8%;width:100%;height:15%;}.yst-passwordred-bottom p{margin-left:10%; width:80%; font-size:1.6rem;color:#000;font-weight: bold;}.redcom-back{width: 40%;margin: 0% 30% 0px;position:fixed;bottom:5%}.yst-receive-con{width: 80%;margin-left: 10%;margin-top: 5px;font-size: 1.3rem;text-indent:2em;}";
                    var first = document.body.firstChild;
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            });
        }else{
           // var gamegetprize=document.getElementById('gamegetprize');
           //  gamegetprize.addEventListener("touchstart", yisutui.moreclicktip, false); 
           alert("亲~每次游戏结束后，只能领取一次口令");
        }

        
    }
    yisutui.rwechatclose=function(){
        // var ystspread=document.getElementById('ystspread-a');
        // if(ystspread){
        //     ystspread.setAttribute('href','#');
        //     setTimeout(function(){
        //         ystspread.setAttribute('href','http://www.yisutui.com');
        //     },1000);
        // }
        
        // var rankform = document.body;
        // rankform.removeChild(rankform.childNodes[0]);
        var isbarrage=document.getElementById('yst-barrage-mask');
        if(isbarrage){
            isbarrage.style.display="block";
        }
        var ystspread=document.getElementById('ystspread-a');
        if(ystspread){
            ystspread.setAttribute('href','#');
            setTimeout(function(){
                ystspread.setAttribute('href','http://www.yisutui.com');
            },1000);
        }
        var redcom=document.getElementById('redcommend');
        redcom.style.display='none';
    }
     yisutui.closeForm=function(){
        var prizeform = document.body;
        prizeform.removeChild(prizeform.childNodes[0]);
    };
    //点击再来一次按钮 20150804 ggb
    yisutui.more = function(hitnum, addnum) {
        //删除掉排行榜的div
        var friendsrank = document.getElementById('friendsrank');
        if (friendsrank) {
            document.getElementById('friendsrank').parentNode.removeChild(document.getElementById('friendsrank'));
        }
        var itemrank = document.getElementById('itemrank');
        if (itemrank) {
            document.getElementById('itemrank').parentNode.removeChild(document.getElementById('itemrank'));
        }
        //删除抽奖和抽取优惠券div
        var lottery = document.getElementById('lottery');
        if (lottery) {
            document.getElementById('lottery').parentNode.removeChild(document.getElementById('lottery'));
        }
        var coupon = document.getElementById('coupon');
        if (coupon) {
            document.getElementById('coupon').parentNode.removeChild(document.getElementById('coupon'));
        }
        //删除红包口令div
        var redcom=document.getElementById('redcommend');
        if(redcom){
            document.getElementById('redcommend').parentNode.removeChild(document.getElementById('redcommend'));
        }
        //抽奖和抽取优惠券监听事件
        var gamegetprize = document.getElementById('gamegetprize');
        if (gamegetprize) {
            if (gamegetprize.removeEventListener) { // // 所有浏览器，除了 IE 8 及更早IE版本
                gamegetprize.removeEventListener("touchstart", yisutui.moreclicktip, false);
            } else if (gamegetprize.detachEvent) { // IE 8 及更早IE版本
                gamegetprize.detachEvent("touchstart", yisutui.moreclicktip);
            }
        }
        var getcoupon = document.getElementById('getcoupon');
        if (getcoupon) {
            //移除监听事件
            if (getcoupon.removeEventListener) { // // 所有浏览器，除了 IE 8 及更早IE版本
                getcoupon.removeEventListener("touchstart", yisutui.moreclicktip, false);
            } else if (getcoupon.detachEvent) { // IE 8 及更早IE版本
                getcoupon.detachEvent("touchstart", yisutui.moreclicktip);
            }
        }
        document.getElementById('yisutui_').style.display = "none";
        if (parseInt(hitnum) < 1) {
            yisutui.nohitnum(addnum);
        }
    };

    //游戏规则悬浮块 20150804 ggb
    // yisutui.gamerule=function(){
    //     var yisutui_ = document.getElementById('gamerule');
    //     if(!yisutui_){
    //         var yisutui__div = document.createElement('div');
    //         var yisutui__css = document.createElement('style');
    //         yisutui__div.id = 'gamerule';
    //         yisutui__div.innerHTML = "<div class='rulebutton' ontouchstart='yisutui.ruleshow()'><img src='"+domain+"/API/img/itemrule.png' width='100%'></div>";
    //         yisutui__css.innerHTML = ".rulebutton{width:3.6rem; height: 10.7rem; position: absolute; top:2rem; left: 0px; z-index: 9999;}";
    //         var first = document.body.firstChild;

    //         document.body.insertBefore(yisutui__div ,first);
    //         document.head.appendChild(yisutui__css);
    //     }
    // };

    //游戏活动规则 20151123 ggb
    yisutui.gamerule = function() {
        Ajax.request("/g/getruletab", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (parseInt(data.status) == 1) {
                    var ruletab = data.ruletab;
                } else {
                    var ruletab = "ruletab.png";
                }
                var yisutui_ = document.getElementById('gamerule');
                if (!yisutui_) {
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'gamerule';

                    yisutui__div.innerHTML = "<div class='ystruletab'><img src='" + domain + "/files/images/" + ruletab + "' ontouchstart='yisutui.ruleshow()'></div>";
                    yisutui__css.innerHTML = ".ystruletab{position: fixed;top: 0;left: 0;z-index: 9996;width: 100%;color: transparent;font: 0/0 a;text-shadow: none;text-align: center;} .ystruletab img {width:6rem;}";

                    var first = document.body.firstChild;
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            },
            failure: function() {
                var yisutui_ = document.getElementById('gamerule');
                if (!yisutui_) {
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'gamerule';

                    yisutui__div.innerHTML = "<div class='ystruletab'><img src='" + domain + "/API/img/ystruletab.png' ontouchstart='yisutui.ruleshow()'></div>";
                    yisutui__css.innerHTML = ".ystruletab{position: fixed;top: 0;left: 0;z-index: 9996;width: 100%;color: transparent;font: 0/0 a;text-shadow: none;text-align: center;} .ystruletab img {width:6rem;}";

                    var first = document.body.firstChild;
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            }
        });

    }

    //游戏规则弹窗 20150805 ggb
    yisutui.ruleshow = function() {
        var yisutui_ = document.getElementById('ruleshow');
        if (!yisutui_) {
            Ajax.request("/g/get_rule_detail", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    // console.log(data);
                    if (parseInt(data.picset) == 1) { //有设置活动规则的相关图片
                        var rulebg = data.itempic.rulebg;
                        var ruleclose = data.itempic.ruleclose;
                        var ruletimepic = data.itempic.ruletimepic;
                        var ruleprizepic = data.itempic.ruleprizepic;
                        var rulehostpic = data.itempic.rulehostpic;
                        var ruletextpic = data.itempic.ruletextpic;
                    } else { //没设置
                        var rulebg = "rulebg.png";
                        var ruleclose = "ruleclose.png";
                        var ruletimepic = "ruletimepic.png";
                        var ruleprizepic = "ruleprizepic.png";
                        var rulehostpic = "rulehostpic";
                        var ruletextpic = "ruletextpic.png";
                    }

                    if (data.code == "1") {
                        var yisutui_ = document.getElementById('ruleshow');
                        if (!yisutui_) {
                            var yisutui__div = document.createElement('div');
                            var yisutui__css = document.createElement('style');
                            yisutui__div.id = 'ruleshow';

                            yisutui__div.innerHTML = "<div class='maincontainer'><div class='back'><img src='" + domain + "/files/images/" + rulebg + "' class='bimg'><div class='yst-rul-con'><div class='yst-rul-text'><div class='active1'><img src='" + domain + "/files/images/" + ruletimepic + "' class='img1'><span class='s1'>" + data.ruletime + "</span></div><div class='active2'><img src='" + domain + "/files/images/" + ruleprizepic + "' class='img1'><span class='s1'>" + data.ruleprize + "</span></div><div class='active2'><img src='" + domain + "/files/images/" + rulehostpic + "' class='img1'><span class='s1'>" + data.rulehost + "</span></div><div class='active2'><img src='" + domain + "/files/images/" + ruletextpic + "' class='img1'><span class='s1'>" + data.rulerule + "</div><div class='active2'></div></div><img src='" + domain + "/files/images/" + ruleclose + "' class='cimg' ontouchstart='yisutui.ruleclose()'></div><p class='s5'>" + data.ruleremark + "</p></div></div>";

                            yisutui__css.innerHTML = ".yst-rul-text{width:100%;height:95%;overflow-y:auto;}.yst-rul-con{position: fixed;width: 80%;height: 70%;left: 10%;top: 12%;font-size: 1.5rem;font-family: 'kaiti';}.maincontainer {width: 100%; height:100%; background-color: rgba(0,0,0,.6); z-index: 10000;}.back{width: 100%;height: 100%; position: fixed;z-index: 10000;background-color: rgba(0,0,0,.6);}.bimg{width: 85%; height:84.4%; position: fixed; top:6.5%; left: 7.8%;}.active1{width: 92%;margin-left:8%;}.img1{width: 22.3%; }.s1{display: block; color: #FFF; margin-left: 7%;  width: 83%; padding-top: 4%;}.active2{width: 92%;margin-top: 3%;margin-left:8%;}.s4{display: block; color: #FFF; margin-left: 3%;  width: 83%; }.s5{font-weight: bold; font-size: 1.6rem; display: block; color: #f12525; position: fixed; top: 83%; left: 0; text-align: center;width: 100%  }.cimg{width: 11.6%; height:6.523%; position: fixed; left: 82%; top: 6.5%;}.content{overflow:auto;position:fixed;padding:8px;background:rgba(0,0,0,0);width: 80%;height: 70%;left: 10%;top: 10%;-webkit-box-sizing:border-box; -moz-box-sizing: border-box; box-sizing: border-box;}"

                            var first = document.body.firstChild;
                            document.body.insertBefore(yisutui__div, first);
                            document.head.appendChild(yisutui__css);
                        }
                    } else {
                        var yisutui_ = document.getElementById('ruleshow');
                        if (!yisutui_) {
                            var yisutui__div = document.createElement('div');
                            var yisutui__css = document.createElement('style');
                            yisutui__div.id = 'ruleshow';
                            yisutui__div.innerHTML = "<div class='maincontainer'><div class='back'><img src='" + domain + "/API/img/relbg.png' class='bimg'><div class='yst-rul-con'><div class='yst-rul-text'><div class='active1'><img src='" + domain + "/API/img/active1.png' class='img1'><span class='s1'>2015年1月25日到12月28日</span></div><div class='active2'><img src='" + domain + "/API/img/active2.png' class='img1'><span class='s1'>参与活动即可有机会获得iPhone6s</span></div><div class='active2'><img src='" + domain + "/API/img/active3.png' class='img1'><span class='s1'>本活动由易速推全程赞助，本活动奖品由易速推提供</span></div><div class='active2'><img src='" + domain + "/API/img/active4.png' class='img1'><span class='s1'>1.体验金不可提现，仅可通过App投资海金仓的体验</span><span class='s1'>2.体验金收益的有效期为自用户获得该笔收益之日起90天， 过期系统自动收回。有效期内用户可使用该收益投资海金仓任何P2P产品。</span><span class='s1'>3.活动过程中发现借用活动漏洞进行违规操作的用户，海金仓将直接取消其参与资格， 收回其所获得的全部体验金及体验投资收益。</span><span class='s1'>4.海金仓有权根据活动的实际情况对活动规则做相应调整。</span></div></div><img src='" + domain + "/API/img/close.png' class='cimg' ontouchstart='yisutui.ruleclose()'></div><p class='s5'>主办方拥有活动最终解释权</p></div></div>";
                            yisutui__css.innerHTML = ".yst-rul-text{width:100%;height:95%;overflow-y:auto;}.yst-rul-con{position: fixed;width: 80%;height: 70%;left: 10%;top: 12%;font-size: 1.5rem;font-family: 'kaiti';}.maincontainer {width: 100%; height:100%; background-color: rgba(0,0,0,.6); z-index: 10000;}.back{width: 100%;height: 100%; position: fixed;z-index: 10000;background-color: rgba(0,0,0,.6);}.bimg{width: 85%; height:84.4%; position: fixed; top:6.5%; left: 7.8%;}.active1{width: 92%;margin-left:8%;}.img1{width: 22.3%; }.s1{display: block; color: #FFF; margin-left: 7%;  width: 83%; padding-top: 4%;}.active2{width: 92%;margin-top: 3%;margin-left:8%;}.s4{display: block; color: #FFF; margin-left: 3%;  width: 83%; }.s5{font-weight: bold; font-size: 1.6rem; display: block; color: #f12525; position: fixed; top: 83%; left: 0; text-align: center;width: 100%  }.cimg{width: 11.6%; height:6.523%; position: fixed; left: 82%; top: 6.5%;}.content{overflow:auto;position:fixed;padding:8px;background:rgba(0,0,0,0);width: 80%;height: 70%;left: 10%;top: 10%;-webkit-box-sizing:border-box; -moz-box-sizing: border-box; box-sizing: border-box;}"
                            var first = document.body.firstChild;
                            document.body.insertBefore(yisutui__div, first);
                            document.head.appendChild(yisutui__css);
                        }
                    }
                    //活动规则弹出方式
                    if (parseInt(data.ruletype) == 2) {
                        document.getElementById('ruleshow').style.display = "block";
                    } else {
                        document.getElementById('ruleshow').style.display = "none";
                    }
                },
                failure: function() {
                    var yisutui_ = document.getElementById('ruleshow');
                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'ruleshow';

                        // yisutui__div = "<div class='content' style=''></div>";
                        // yisutui__div.innerHTML = "<div class='maincontainer'><div class='rulecontainer'><div class='detailtop'><img src='"+domain+"/API/img/ruletitle.png'></div><div class='ruledetail' style='text-align:left;'><div class='ruletext'><div class='texttext' id='rule-msg' style='width: 100%;height: 100%;margin: 0.2rem;overflow-y: auto;font-family:Arial,Hiragino Sans GB,Microsoft YaHei,Simsun,sans-serif;word-wrap: break-word;'></div></div></div><div class='detailbottom' ontouchstart='yisutui.ruleclose()'><img src='"+domain+"/API/img/known.png'></div></div></div>";
                        // yisutui__css.innerHTML = ".maincontainer {width: 100%; height:100%; background-color: rgba(0,0,0,.6); z-index: 10000;}  .rulecontainer{z-index: 10000; width: 80%; height: 60%; background-color: #ff6599; border-radius: 0.5rem; position: absolute; top: 20%; left: 10%;}.ruletext {width: 90%; height: 80%; font-size:1.4rem; position: absolute; top: 10%; background-color: #fff; left: 5%; border: 0.2rem solid #ff0032;overflow: hidden;} .detailtop {text-align: center; margin-top: -2.4rem;} .detailbottom {position: absolute; bottom: -2.1rem; text-align: center; width: 100%;} .texttext {color:#000}.txtstyle{font-size: 1.5rem;font-weight: 500;line-height: 1.5rem;color: #FF3366;}";

                        yisutui__div.innerHTML = "<div class='maincontainer'><div class='back'><img src='" + domain + "/API/img/relbg.png' class='bimg'><div class='yst-rul-con'><div class='yst-rul-text'><div class='active1'><img src='" + domain + "/API/img/active1.png' class='img1'><span class='s1'>2015年1月25日到12月28日</span></div><div class='active2'><img src='" + domain + "/API/img/active2.png' class='img1'><span class='s1'>参与活动即可有机会获得iPhone6s</span></div><div class='active2'><img src='" + domain + "/API/img/active3.png' class='img1'><span class='s1'>本活动由周杰伦全程赞助，本活动奖品由苹果公司提供</span></div><div class='active2'><img src='" + domain + "/API/img/active4.png' class='img1'><span class='s1'>1.体验金不可提现，仅可通过App投资海金仓的体验</span><span class='s1'>2.体验金收益的有效期为自用户获得该笔收益之日起90天， 过期系统自动收回。有效期内用户可使用该收益投资海金仓任何P2P产品。</span><span class='s1'>3.活动过程中发现借用活动漏洞进行违规操作的用户，海金仓将直接取消其参与资格， 收回其所获得的全部体验金及体验投资收益。</span><span class='s1'>4.海金仓有权根据活动的实际情况对活动规则做相应调整。</span></div></div><img src='" + domain + "/API/img/close.png' class='cimg' ontouchstart='yisutui.ruleclose()'></div><p class='s5'>主办方拥有活动最终解释权</p></div></div>";
                        yisutui__css.innerHTML = ".yst-rul-text{width:100%;height:95%;overflow-y:auto;}.yst-rul-con{position: fixed;width: 80%;height: 70%;left: 10%;top: 12%;font-size: 1.5rem;font-family: 'kaiti';}.maincontainer {width: 100%; height:100%; background-color: rgba(0,0,0,.6); z-index: 10000;}.back{width: 100%;height: 100%; position: fixed;z-index: 10000;background-color: rgba(0,0,0,.6);}.bimg{width: 85%; height:84.4%; position: fixed; top:6.5%; left: 7.8%;}.active1{width: 92%;margin-left:8%;}.img1{width: 22.3%; }.s1{display: block; color: #FFF; margin-left: 7%;  width: 83%; padding-top: 4%;}.active2{width: 92%;margin-top: 3%;margin-left:8%;}.s4{display: block; color: #FFF; margin-left: 3%;  width: 83%; }.s5{font-weight: bold; font-size: 1.6rem; display: block; color: #f12525; position: fixed; top: 83%; left: 0; text-align: center;width: 100%  }.cimg{width: 11.6%; height:6.523%; position: fixed; left: 82%; top: 6.5%;}.content{overflow:auto;position:fixed;padding:8px;background:rgba(0,0,0,0);width: 80%;height: 70%;left: 10%;top: 10%;-webkit-box-sizing:border-box; -moz-box-sizing: border-box; box-sizing: border-box;}"
                        var first = document.body.firstChild;
                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);

                        //document.getElementById('');
                        // document.getElementById("rule-msg").innerText = "活动时间：" + data.ruletime + "活动奖品："+data.ruleprize + "游戏规则："+data.rulerule;
                        // document.getElementById("rule-msg").innerHTML = "<span class='txtstyle'>活动时间：</span><br>"+data.ruletime+"<br><span class='txtstyle'>活动奖品：</span><br>"+ data.ruleprize +"<br><span class='txtstyle'>游戏规则：</span><br>" + data.rulerule;
                        // setTimeout(function(){
                        //     document.getElementById("rule-msg").style.overflowX = "hidden";
                        // }, 50);
                    }
                    document.getElementById('ruleshow').style.display = "none";
                }
            });
        } else {
            document.getElementById('ruleshow').style.display = "block";
        }

    };
    //游戏规则弹窗关闭 20150805 ggb
    yisutui.ruleclose = function() {
        // var yisutui_=document.body;
        // yisutui_.removeChild(yisutui_.childNodes[0]);
        document.getElementById('ruleshow').style.display = "none";
    };
    //排行榜活动规则弹窗关闭 20150805 ggb
    yisutui.closerules = function() {
            // var yisutui_=document.body;
            // yisutui_.removeChild(yisutui_.childNodes[0]);
            document.getElementById('rankrule').style.display = "none";
        }
        //排行榜提交成绩 20150725 ggb
    yisutui.ranksubmit = function(score) {
        //获取密匙
        Ajax.request("/g/getrankkey", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    rgamescore = enmimi(score, 'ENCODE', data.key);
                    Ajax.request("/g/addrank", {
                        async: true,
                        method: "POST",
                        encode: "UTF-8",
                        data: {
                            itemid: itemid,
                            keyid: data.keyid,
                            score: rgamescore
                        },
                        success: function(xhr) {
                            var data = JSON.parse(xhr.responseText);
                            if (data.code == "1") {
                                // view("修改成功！");    
                                console.log("保存成功");
                            } else {
                                alert(data.msg);
                            }
                            yisutui.itemrank(); //预加载总排行榜数据,等分数提交成功再加载
                        },
                        failure: function() {
                            console.log("网络异常！");
                            yisutui.itemrank(); //预加载总排行榜数据,等分数提交成功再加载
                        }
                    });
                } else {
                    console.log('Get key fail');
                    yisutui.itemrank(); //预加载总排行榜数据,等分数提交成功再加载
                }
            },
            failure: function() {
                console.log("网络异常！");
                yisutui.itemrank(); //预加载总排行榜数据,等分数提交成功再加载
            }
        });

    };
    //排行榜列表 20150807 ggb
    yisutui.itemrank = function() {
        var yisutui_ = document.getElementById('itemrank');
        if (!yisutui_) {
            var yisutui__div = document.createElement('div');
            var yisutui__css = document.createElement('style');
            yisutui__div.id = 'itemrank';
            var yst_top1 = domain + "/API/img/jinpai.png";
            var yst_top2 = domain + "/API/img/yinpai.png";
            var yst_top3 = domain + "/API/img/tongpai.png";
            var yst_morerank = domain + "/API/img/xiala.png";
            var yst_back = domain + "/API/img/rankbg.png";
            var yst_goback = domain + "/API/img/fanhui.png";
            var yst_rule_menu = "/API/img/f_rank.png";
            var yst_exch_prize = domain + "/files/images/" + rankruleicon;
            yisutui__div.innerHTML = "<div class='rankcontainer'><div class='yst-rank-box'><img src='" + yst_back + "' class='yst_back' id='yst-rank-bg' style='-webkit-user-select: none;user-select: none;'><div class='yst-rank1'><div class='yst-rank-top3'><ul style='margin:0;padding:0;overflow:auto;'><li class='yst-top2'><img class='t2img' id='yst-wxtop2' style='-webkit-user-select: none;user-select: none;'><img class='yinpai' id='yinpai' style='-webkit-user-select: none;user-select: none;'><div class='s21' id='yst-wxtop2-nickname'></div><div class='s22' id='yst-wxtop2-rank'></div></li><li class='yst-top1'><img class='t1img' id='yst-wxtop1' style='-webkit-user-select: none;user-select: none;'><img src='" + yst_top1 + "' class='jinpai' style='-webkit-user-select: none;user-select: none;'><div class='s11' id='yst-wxtop1-nickname'></div><div class='s12' id='yst-wxtop1-rank'></div></li><li class='yst-top3'><img class='t3img' id='yst-wxtop3' style='-webkit-user-select: none;user-select: none;'><img class='tongpai' id='tongpai' style='-webkit-user-select: none;user-select: none;'><div class='s31' id='yst-wxtop3-nickname'></div><div class='s32' id='yst-wxtop3-rank'></div></li></ul><div class='xian'></div></div><div class='yst-rank-con'><div id='lfg-style'></div><ul class='rank-container' id='yst-rank-container1'></ul><img src='" + yst_morerank + "' class='xiala' id='all-yst-onload' style='-webkit-user-select: none;user-select: none;' ontouchstart=yisutui.onload()></div><div><img src='" + yst_goback + "' class='fanhui' ontouchstart='yisutui.rankback()' id='yst-fanhui' style='-webkit-user-select: none;user-select: none;'><img src='" + yst_rule_menu + "' class='yst-all-rank' id='yst-all-rank' ontouchstart='yisutui.friendsrank()' style='-webkit-user-select: none;user-select: none;'></div></div><img src='" + yst_exch_prize + "' id='yst-duijiang' class='duijiang' ontouchstart='yisutui.rankrule()' style='-webkit-user-select: none;user-select: none;'></div></div>";
            yisutui__css.innerHTML = ".rankcontainer{width:100%; height:100%; z-index:10002;position: fixed; top: 0; left: 0;}.yst_back{width: 82%;height: 86%;position: fixed;left: 9%;top: 4%;}.yst-rank-box{width:100%;height:100%;position:fixed;left:0;top:0;background:rgba(0,0,0,0.6);z-index:101}.yst-rank1{width: 80%;height: 90%;position: fixed;left: 10%;top: 4%;overflow: hidden;}.yst-rank-con{width:100%;height:55%;overflow-y:auto;color:#fff;position:relative;top:7%}.yst-rank-top3{width: 100%;height: 26%;position: relative;top: 7%;}.yst-top1{list-style-type:none;width:33.333%;float:left;position:relative;margin-top:7.5%;}.yst-top2{list-style-type:none;width:33.333%;float:left;position:relative;margin-top:11.5%;}.yst-top3{list-style-type:none;width:33.333%;float:left;position:relative;margin-top:11.5%;}.t1img{border-radius:100%;width:64%;margin-left:18%;position:relative}.jinpai{width:15%;position:relative;margin-top:2%;margin-left:42.5%;}.s11{color:#fff;font-size:0.7rem;position:relative;width: 100%;text-align: center;-webkit-user-select: none;user-select: none;}.s12{color:#fff;font-size: 1rem;position: relative;width: 100%;text-align: center;-webkit-user-select: none;user-select: none;}.t2img{border-radius:100%;width:52%;margin-left:24%;position:relative}.yinpai{width:15%;position:relative;margin-top:2%;margin-left:42.5%;}.s21{color:#fff;font-size:0.7rem;position:relative;width: 100%;text-align: center;-webkit-user-select: none;user-select: none;}.s22{color:#fff;font-size: 1rem;position: relative;width: 100%;text-align: center;-webkit-user-select: none;user-select: none;}.t3img{border-radius:100%;width:52%;margin-left:24%;position:relative;}.tongpai{width:15%;position:relative;margin-top:2%;margin-left:42.5%;}.s31{color:#fff;font-size:0.7rem;position:relative;width: 100%;text-align: center;}.s32{color:#fff;font-size:1rem;position: relative;width: 100%;text-align: center;}.xian{width:84%;border-bottom:1px solid #fff;margin: auto;}.paiming4{width:7%;top:23%;left:5%;position:absolute}.xian1{position:absolute;top:95%;left:3%;width:87.5%;border-bottom:2px solid #fff}.xiala{width:8%;position:relative;margin-left:45.5%;display:none;margin-bottom: 6%;margin-top:3%;}.fanhui{position:fixed;top:83%;left:15%;width:30%}.yst-all-rank{position:fixed;top:83%;left:54%;width:30%}.wire{position:absolute;top:97%;left:7%;width:84%;border-bottom:1px solid #7e7b7b}.yst-top4{position:relative;overflow:auto;padding-top: 2%;}.round{width:28px;height:28px;border:1px solid #fff;border-radius:100%;text-align:center;font-size:17px;line-height:28px;float:left;}.t4img{border-radius:100%;width:13%;margin-left:3%;margin-bottom:1%;float:left;}.s41{font-size:0.7rem;float:left;margin-left:2%;color:#fff;-webkit-user-select: none;user-select: none;}.s42{color: #fff;font-size: 1rem;float: right;-webkit-user-select: none;user-select: none;}.wire1{border-bottom:1px solid #7e7b7b;width: 100%;float: left;}.rank-container{margin:0;padding:0}.rank-container li{list-style-type:none;margin:auto;width:84%}.drop-down{width:8%;position:relative;margin-left:46%;margin-top:2%}.duijiang{position: fixed;width: 8%;top: 30%;}";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui__div, first);
            document.head.appendChild(yisutui__css);
            if (marketing != "3") {
                document.getElementById('yst-duijiang').style.display = "none";
            }
            Ajax.request("/g/getitemrank", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    current_page: '1'
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (parseInt(data.picset) == 1) { //有设置总排行榜的相关图片
                        var rankbg = domain + "/files/images/" + data.itempic.rankbg;
                        var rankback = domain + "/files/images/" + data.itempic.rankback;
                        var frank = domain + "/files/images/" + data.itempic.frank;
                    } else { //没设置
                        var rankbg = domain + "/files/images/rankbg.png";
                        var rankback = domain + "/files/images/rankback.png";
                        var frank = domain + "/files/images/frank.png";
                    }
                    document.getElementById('yst-rank-bg').src = rankbg;
                    document.getElementById('yst-fanhui').src = rankback;
                    document.getElementById('yst-all-rank').src = frank;
                    if (data.code == "1") {
                        // var formone="<div class='formone22'>";
                        var formone = "";
                        for (var o in data.rank) {
                            if (typeof data['rank'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                                if (data['rank'][o]['nickname'].length > 5) {
                                    data['rank'][o]['nickname'] = data['rank'][o]['nickname'].substr(0, 4) + "*";
                                }
                                var i = parseInt(o, 10);
                                if (i >= 3) {
                                    formone += "<li id='addli'><div class='yst-top4'><div class='round' id='yst_rank_count' style='-webkit-user-select: none;user-select: none;'>" + (i + 1) + "</div><img src='" + data['rank'][o]['avatar'] + "' class='t4img' style='-webkit-user-select: none;user-select: none;'><span class='s41' id='wx_nickname' style='-webkit-user-select: none;user-select: none;'>" + data['rank'][o]['nickname'] + "</span><span class='s42' id='you_score' style='-webkit-user-select: none;user-select: none;'>" + data['rank'][o]['score'] + "</span><div class='wire1' style='-webkit-user-select: none;user-select: none;'></div></div></li>";
                                } else {
                                    switch (i) {
                                        case 0:
                                            document.getElementById('yst-wxtop1').src = data['rank'][o]['avatar'];
                                            document.getElementById('yst-wxtop1-nickname').innerText = data['rank'][o]['nickname'];
                                            document.getElementById('yst-wxtop1-rank').innerText = data['rank'][o]['score'];
                                            break;
                                        case 1:
                                            document.getElementById('yinpai').src = yst_top2;
                                            document.getElementById('yst-wxtop2').src = data['rank'][o]['avatar'];
                                            document.getElementById('yst-wxtop2-nickname').innerText = data['rank'][o]['nickname'];
                                            document.getElementById('yst-wxtop2-rank').innerText = data['rank'][o]['score'];
                                            break;
                                        case 2:
                                            document.getElementById('tongpai').src = yst_top3;
                                            document.getElementById('yst-wxtop3').src = data['rank'][o]['avatar'];
                                            document.getElementById('yst-wxtop3-nickname').innerText = data['rank'][o]['nickname'];
                                            document.getElementById('yst-wxtop3-rank').innerText = data['rank'][o]['score'];
                                            break;
                                    }
                                }
                                if (i == 9) { // 点击加载更多现实图标
                                    document.getElementById('all-yst-onload').style.display = "block";
                                }
                            }
                        }
                        document.getElementById('yst-rank-container1').innerHTML = formone;

                        setTimeout(function() {
                            if (document.getElementById('addli') != null) {
                                var item_H = document.getElementById('addli').offsetHeight;
                                var str = "<style>.round{margin-top:1.5%;font-size:1.5rem;}.s42,.s41{line-height:3.4rem;font-size: 1.4rem;}.t4img{margin-top:0.3%;}</style>";
                                document.getElementById('lfg-style').innerHTML = str;
                            }
                        }, 80);
                    } else {
                        alert('抱歉，网络不稳定，请重玩游戏获取成绩。');
                    }
                },
                failure: function() {
                    alert("抱歉，网络不稳定，请重玩游戏获取成绩。");
                }
            });
            document.getElementById('itemrank').style.display = "none";
        } else {
            var yisutui_itemrank = document.getElementById('friendsrank');
            if (yisutui_itemrank) {
                document.getElementById('friendsrank').style.display = "none";
            } else {
                yisutui.friendsrank(); //进入总排行榜再预加载好友排行榜数据
            }
            document.getElementById('itemrank').style.display = "block";
        }

    };
    //红包排行榜
    yisutui.itemred = function() {

        var yisutui_ = document.getElementById('itemred');
        if (!yisutui_) {
            var yisutui__div = document.createElement('div');
            var yisutui__css = document.createElement('style');
            yisutui__div.id = 'itemred';
            var yst_drop = domain + "/API/img/drop_down.png";
            yisutui__div.innerHTML = "<div class='yst-red'><div class='yst-red-top'><div class='yst-count-frend'><ul><li class='yst-count-red1' id='count-red' >总红包榜</li><li class='yst-frend-red1' id='frend-red' ontouchstart='yisutui.friendsred()'>好友红包榜</li></ul></div></div><div class='yst-red-money' id='yst-all-red'></div><div class='yst-red-con'><ul id='red-container1'></ul><img src='" + yst_drop + "' class='redrop-down' id='all-yst-dropdown' style='-webkit-user-select: none;user-select: none;' ontouchstart=yisutui.redload()><div class='yst-nomore1' id='yst-nomore1'>已经到底，没有更多了</div></div><div class='yst-red-bottom' id='yst-red-bottom'><div class='yst-red-back' id='yst-red-back' ontouchstart='yisutui.redrankback()'>返回</div></div></div>";
            yisutui__css.innerHTML = "body{font-family: Microsoft YaHei, KaiTi, Helvetica, Tahoma;}.yst-red{background: #fff;width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:10010;}.yst-red-top{width: 100%;height:12%;position:relative}.yst-count-frend{width:60%;border-radius: 35px;overflow: auto;position:absolute;top:50%;left:50%; transform: translate(-50%,-50%);-webkit-transform: translate(-50%,-50%);}.yst-count-frend ul li{list-style: none;float: left;width: 48.5%;text-align: center;border:1px solid #f85959;font-size: 1.5rem;padding: 3% 0;}.yst-count-red1{border-radius: 35px 0 0 35px;color: #e5f908;background:#f85959}.yst-frend-red1{border-radius: 0 35px 35px 0; color:#f85959; background:#fff;}.yst-red-money{height: 25px; width: 100%;background: #eee;color: #767674;font-size: 1.2rem;text-indent: 2em;line-height: 25px}.yst-red-con{height: 76%; width: 104%;overflow-y: auto;position: relative;}.yst-red-con ul{width:96%;overflow:auto;}.yst-red-con ul li{width: 90%;margin-left: 5%;}.yst-red-licon{position: relative;}.t4img {border-radius: 100%;width: 15%;margin-top: 1.5%;margin-bottom: 1.5%;float: left;}.wire1 {border-bottom: 1px solid #dcdcdc;clear: both;}.red-name-time{float: left;margin-top: 3%;margin-left: 5%;}.red-time{display: block;color: #888; font-size: 1.3rem;margin-top: 4px;}.red-name{display: block;font-size: 1.5rem;font-weight: bold;}.red-money{float: right;margin-top: 5.5%;font-size: 1.8rem;font-weight: bold;}.redrop-down{width: 5%;position: relative;padding: 4%;margin-left: 42%;display:none;}.yst-red-bottom{width: 100%; background: #f85959;height: 8%;position: fixed;bottom: 0;}.yst-red-back{width:26%;border-radius: 35px;overflow: auto;text-align: center;background: #963737;color: #fff;padding: 2% 0;margin-left:37%}#itemred{z-index:10010;height:100%}.yst-nomore1{margin: 3% 0;width: 100%;text-align: center;color: #888;display:none;}";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui__div, first);
            document.head.appendChild(yisutui__css);
            var abottom=document.getElementById('yst-red-bottom').offsetHeight;
            var aback=document.getElementById('yst-red-back').offsetHeight;
            var martop=(abottom-aback)/2;
            document.getElementById('yst-red-back').style.marginTop=martop+'px';
            if (marketing != "3") {
                // document.getElementById('yst-duijiang').style.display = "none";
            }
            Ajax.request("/g/getitemred", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    current_page: '1'
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    // if (parseInt(data.picset) == 1) { //有设置总排行榜的相关图片
                    //     var rankbg = domain + "/files/images/" + data.itempic.rankbg;
                    //     var rankback = domain + "/files/images/" + data.itempic.rankback;
                    //     var frank = domain + "/files/images/" + data.itempic.frank;
                    // } else { //没设置
                    //     var rankbg = domain + "/files/images/rankbg.png";
                    //     var rankback = domain + "/files/images/rankback.png";
                    //     var frank = domain + "/files/images/frank.png";
                    // }
                    // document.getElementById('yst-rank-bg').src = rankbg;
                    // document.getElementById('yst-fanhui').src = rankback;
                    // document.getElementById('yst-all-rank').src = frank;
                    if (data.code == "1") {
                        // var formone="<div class='formone22'>";
                        var formone = "";
                        var formall = "";
                        formall += "<p>已发送<span id='yst-countred'>" + data['count'] + "</span>个红包，总金额<span id='yst-countmoney'>" + data['allamount'] + "</span>元</p>"
                        document.getElementById('yst-all-red').innerHTML = formall;
                        for (var o in data.red) {

                            if (typeof data['red'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                                if (data['red'][o]['nickname'].length > 5) {
                                    data['red'][o]['nickname'] = data['red'][o]['nickname'].substr(0, 4) + "*";
                                }
                                var i = parseInt(o, 10);
                                if (i >= 0) {
                                    var d = new Date(parseInt(data['red'][o]['addtime']) * 1000);
                                    var month = d.getMonth() + 1;
                                    var date = d.getDate();
                                    var hour = d.getHours();
                                    var minute = d.getMinutes();
                                    var now = month + "-" + date + "   " + hour + ":" + minute;

                                    // var now = new Date(parseInt(data['red'][o]['addtime']) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
                                    formone += "<li id='red-addli1'><div class='yst-red-licon'><img src='" + data['red'][o]['avatar'] + "' class='t4img' id='yst-headimg' style='-webkit-user-select: none;user-select: none;'><div class='red-name-time'><span class='red-name' id='yst-redname' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['nickname'] + "</span><span class='red-time' id='yst-redtime' style='-webkit-user-select: none;user-select: none;'>" + now + "</span></div><span class='red-money'><span id='yst-redmoney' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['redamount'] + "</span>元</span><div class='wire1'></div></div></li>";


                                }
                                if (i == 9) { // 点击加载更多现实图标
                                    document.getElementById('all-yst-dropdown').style.display = "block";
                                }
                            }
                        }
                        document.getElementById('red-container1').innerHTML = formone;

                        // setTimeout(function() {
                        //     if (document.getElementById('red-addli1') != null) {
                        //         var item_H = document.getElementById('red-addli1').offsetHeight;
                        //         var str = "<style>.round{margin-top:1.5%;font-size:1.5rem;}.s42,.s41{line-height:3.4rem;font-size: 1.4rem;}.t4img{margin-top:0.3%;}</style>";
                        //         document.getElementById('lfg-style').innerHTML = str;
                        //     }
                        // }, 80);
                    } else {
                        // alert('暂无人获得红包，赶紧去玩游戏抢红包吧！');
                    }
                },
                failure: function() {
                    alert("网络异常！");
                }
            });
            document.getElementById('itemred').style.display = "none";
        } else {
            var yisutui_itemred = document.getElementById('friendsed');
            if (yisutui_itemred) {
                document.getElementById('friendsred').style.display = "none";
            } else {
                yisutui.friendsred(); //进入总排行榜再预加载好友排行榜数据
            }
            document.getElementById('itemred').style.display = "block";
        }

    };
    // 红包加载更多  
    yisutui.redload = function() {
        var pagesindexof = ystred_index;
        var reddataurl = "/g/getitemred";
        Ajax.request(reddataurl, {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                current_page: '' + pagesindexof
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    var formone = "";
                    for (var o in data.red) {
                        if (typeof data['red'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                            if (data['red'][o]['nickname'].length > 5) {
                                data['red'][o]['nickname'] = data['red'][o]['nickname'].substr(0, 4) + "*";
                            }
                            var i = parseInt(o, 10);
                            var d = new Date(parseInt(data['red'][o]['addtime']) * 1000);
                            var month = d.getMonth() + 1;
                            var date = d.getDate();
                            var hour = d.getHours();
                            var minute = d.getMinutes();
                            var now = month + "-" + date + "   " + hour + ":" + minute;
                            // var now = new Date(parseInt(data['red'][o]['addtime']) * 1000).toLocaleString();
                            formone += "<li id='red-addli1'><div class='yst-red-licon'><img src='" + data['red'][o]['avatar'] + "' class='t4img' id='yst-headimg' style='-webkit-user-select: none;user-select: none;'><div class='red-name-time'><span class='red-name' id='yst-redname' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['nickname'] + "</span><span class='red-time' id='yst-redtime' style='-webkit-user-select: none;user-select: none;'>" + now + "</span></div><span class='red-money'><span id='yst-redmoney' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['redamount'] + "</span>元</span><div class='wire1'></div></div></li>";
                        }
                    }
                    var more_containter = document.createElement('div');
                    more_containter.innerHTML = formone;
                    var ele = document.getElementById('red-container1');
                    ele.appendChild(more_containter);
                    ystred_index++; // 页数增加
                } else {

                    document.getElementById('all-yst-dropdown').style.display = 'none';
                    document.getElementById('yst-nomore1').style.display = 'block';
                }
            },
            failure: function() {
                alert("网络异常！");
            }
        });
    };

    //红包返回功能 20150808 ggb
    yisutui.redback = function() {

        ystred_index = 2;
        ystred_friend_index = 2;
        // ystrank_flag = "more";
        // var yisutui_=document.body;
        // yisutui_.removeChild(yisutui_.childNodes[0]);
        document.getElementById('itemred').style.display = "none";
        document.getElementById('friendsred').style.display = "none";

    };
    yisutui.redrankback=function(e){
         if(e && e.stopPropagation){
            //W3C取消冒泡事件
                e.stopPropagation();
            }else{
            //IE取消冒泡事件
            window.event.cancelBubble = true;
            }
        ystred_index = 2;
        ystred_friend_index = 2;
        var ystspread=document.getElementById('ystspread-a');
        if(ystspread){
            ystspread.setAttribute('href','#');
            setTimeout(function(){
                ystspread.setAttribute('href','http://www.yisutui.com');
            },1000);
        }
        document.getElementById('itemred').style.display = "none";
        document.getElementById('friendsred').style.display = "none";
        
    }
    //好友红包排行榜
    yisutui.friendsred = function() {
        var yisutui_ = document.getElementById('friendsred');
        if (!yisutui_) {
            var yisutui__div = document.createElement('div');
            var yisutui__css = document.createElement('style');
            yisutui__div.id = 'friendsred';
            var yst_drop = domain + "/API/img/drop_down.png";

            yisutui__div.innerHTML = "<div class='yst-red'><div class='yst-red-top'><div class='yst-count-frend'><ul><li class='yst-count-red2' id='count-red' ontouchstart='yisutui.itemred()'>总红包榜</li><li class='yst-frend-red2' id='frend-red'>好友红包榜</li></ul></div></div><div class='yst-red-money' id='yst-friends-red'></div><div class='yst-red-con'><ul id='red-container2'></ul><img src='" + yst_drop + "' class='redrop-down' id='f-yst-dropdown' style='-webkit-user-select: none;user-select: none;' ontouchstart=yisutui.fredload()><div class='yst-nomore2' id='yst-nomore2'>已经到底，没有更多了</div></div><div class='yst-red-bottom' id='yst-red-bottom'><div class='yst-red-back' id='yst-red-back' ontouchstart='yisutui.redrankback()'>返回</div></div></div>";
            yisutui__css.innerHTML = "body{font-family: Microsoft YaHei, KaiTi, Helvetica, Tahoma;}.yst-red{background: #fff;width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:10010;}.yst-red-top{width: 100%;height:12%;position:relative}.yst-count-frend{width:60%;border-radius: 35px;overflow: auto;position:absolute;top:50%;left:50%; transform: translate(-50%,-50%);-webkit-transform: translate(-50%,-50%);}.yst-count-frend ul li{list-style: none;float: left;width: 48.5%;text-align: center;border:1px solid #f85959;font-size: 1.5rem;padding: 3% 0;}.yst-count-red2{border-radius: 35px 0 0 35px;color:#f85959; background:#fff;}.yst-frend-red2{border-radius: 0 35px 35px 0; color: #e5f908;background:#f85959}.yst-red-money{height: 25px; width: 100%;background: #eee;color: #767674;font-size: 1.2rem;text-indent: 2em;line-height: 25px}.yst-red-con{height: 76%; width: 104%;overflow-y: auto;position: relative;}.yst-red-con ul{width:96%;overflow:auto;}.yst-red-con ul li{width: 90%;margin-left: 5%;}.yst-red-licon{position: relative;}.t4img {border-radius: 100%;width: 15%;margin-top: 1.5%;margin-bottom: 1.5%;float: left;}.wire1 {border-bottom: 1px solid #dcdcdc;clear: both;}.red-name-time{float: left;margin-top: 3%;margin-left: 5%;}.red-time{display: block;color: #888; font-size: 1.3rem;margin-top: 3px;}.red-name{display: block;font-size: 1.5rem;font-weight: bold;}.red-money{float: right;margin-top: 5.5%;font-size: 1.8rem;font-weight: bold;}.redrop-down{width: 5%;position: relative;padding: 4%;margin-left: 42%; display:none;}.yst-red-bottom{width: 100%; background: #f85959;height: 8%;position: fixed;bottom: 0;}.yst-red-back{width:26%;border-radius: 35px;overflow: auto;text-align: center;background: #963737;color: #fff;padding: 2% 0;margin-left:37%;}#friendsred{z-index:10010;height:100%}.yst-nomore2{margin: 3% 0;width: 100%;text-align: center;color: #888;display:none;}";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui__div, first);
            document.head.appendChild(yisutui__css);
            var abottom=document.getElementById('yst-red-bottom').offsetHeight;
            var aback=document.getElementById('yst-red-back').offsetHeight;
            var martop=(abottom-aback)/2;
            document.getElementById('yst-red-back').style.marginTop=martop+'px';
            if (marketing != "3") {
                // document.getElementById('yst-duijiang').style.display = "none";
            }
            Ajax.request("/g/getfriendred", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    current_page: '1'
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    // if (parseInt(data.picset) == 1) { //有设置总排行榜的相关图片
                    //     var rankbg = domain + "/files/images/" + data.itempic.rankbg;
                    //     var rankback = domain + "/files/images/" + data.itempic.rankback;
                    //     var frank = domain + "/files/images/" + data.itempic.frank;
                    // } else { //没设置
                    //     var rankbg = domain + "/files/images/rankbg.png";
                    //     var rankback = domain + "/files/images/rankback.png";
                    //     var frank = domain + "/files/images/frank.png";
                    // }
                    // document.getElementById('yst-rank-bg').src = rankbg;
                    // document.getElementById('yst-fanhui').src = rankback;
                    // document.getElementById('yst-all-rank').src = frank;
                    if (data.code == "1") {
                        // var formone="<div class='formone22'>";
                        var formone = "";
                        var formall = "";
                        formall += "<p>已发送<span id='yst-fcountred'>" + data['count'] + "</span>个红包，总金额<span id='yst-fcountmoney'>" + data['allamount'] + "</span>元</p>"
                        document.getElementById('yst-friends-red').innerHTML = formall;
                        for (var o in data.red) {
                            if (typeof data['red'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                                if (data['red'][o]['nickname'].length > 5) {
                                    data['red'][o]['nickname'] = data['red'][o]['nickname'].substr(0, 4) + "*";
                                }
                                var i = parseInt(o, 10);
                                if (i >= 0) {
                                    var d = new Date(parseInt(data['red'][o]['addtime']) * 1000);
                                    var month = d.getMonth() + 1;
                                    var date = d.getDate();
                                    var hour = d.getHours();
                                    var minute = d.getMinutes();
                                    var now = month + "-" + date + "   " + hour + ":" + minute;
                                    // var now = new Date(parseInt(data['red'][o]['addtime']) * 1000).toLocaleString();
                                    formone += "<li id='red-addli1'><div class='yst-red-licon'><img src='" + data['red'][o]['avatar'] + "' class='t4img' id='yst-headimg' style='-webkit-user-select: none;user-select: none;'><div class='red-name-time'><span class='red-name' id='yst-redname' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['nickname'] + "</span><span class='red-time' id='yst-redtime' style='-webkit-user-select: none;user-select: none;'>" + now + "</span></div><span class='red-money'><span id='yst-redmoney' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['redamount'] + "</span>元</span><div class='wire1'></div></div></li>";

                                }
                                if (i == 9) { // 点击加载更多现实图标
                                    document.getElementById('f-yst-dropdown').style.display = "block";
                                }
                            }
                        }
                        document.getElementById('red-container2').innerHTML = formone;

                        // setTimeout(function() {
                        //     if (document.getElementById('addli') != null) {
                        //         var item_H = document.getElementById('addli').offsetHeight;
                        //         var str = "<style>.round{margin-top:1.5%;font-size:1.5rem;}.s42,.s41{line-height:3.4rem;font-size: 1.4rem;}.t4img{margin-top:0.3%;}</style>";
                        //         document.getElementById('lfg-style').innerHTML = str;
                        //     }
                        // }, 80);
                    } else {
                        // alert('暂无人获得红包，赶紧去玩游戏抢红包吧！');
                    }
                },
                failure: function() {
                    alert("网络异常！");
                }
            });
            document.getElementById('itemred').style.display = "none";
        } else {
            var yisutui_itemred = document.getElementById('itemred');
            if (yisutui_itemred) {
                document.getElementById('itemred').style.display = "none";
            } else {
                yisutui.itemred(); //进入总排行榜再预加载好友排行榜数据
            }
            document.getElementById('friendsred').style.display = "block";
        }

    };
    // 好友红包加载更多  
    yisutui.fredload = function() {
        var pagesindexof = ystred_friend_index;
        var reddataurl = "/g/getfriendred";
        Ajax.request(reddataurl, {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                current_page: '' + pagesindexof
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    var formone = "";
                    for (var o in data.red) {
                        if (typeof data['red'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                            if (data['red'][o]['nickname'].length > 5) {
                                data['red'][o]['nickname'] = data['red'][o]['nickname'].substr(0, 4) + "*";
                            }
                            var i = parseInt(o, 10);
                            var d = new Date(parseInt(data['red'][o]['addtime']));
                            var month = d.getMonth() + 1;
                            var date = d.getDate();
                            var hour = d.getHours();
                            var minute = d.getMinutes();
                            var now = month + "-" + date + "   " + hour + ":" + minute;
                            formone += "<li id='red-addli1'><div class='yst-red-licon'><img src='" + data['red'][o]['avatar'] + "' class='t4img' id='yst-headimg' style='-webkit-user-select: none;user-select: none;'><div class='red-name-time'><span class='red-name' id='yst-redname' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['nickname'] + "</span><span class='red-time' id='yst-redtime' style='-webkit-user-select: none;user-select: none;'>" + now + "</span></div><span class='red-money'><span id='yst-redmoney' style='-webkit-user-select: none;user-select: none;'>" + data['red'][o]['redamount'] + "</span>元</span><div class='wire1'></div></div></li>";
                        }
                    }
                    var more_containter = document.createElement('div');
                    more_containter.innerHTML = formone;
                    var ele = document.getElementById('red-container2');
                    ele.appendChild(more_containter);
                    ystred_friend_index++; // 页数增加
                } else {

                    document.getElementById('f-yst-dropdown').style.display = 'none';
                    document.getElementById('yst-nomore2').style.display = 'block';

                }
            },
            failure: function() {
                alert("网络异常！");
            }
        });
    };
    // 加载更多  20151204 by fg
    yisutui.onload = function() {
        var pagesindexof = ystpage_index;
        var rankdataurl = "/g/getitemrank";
        Ajax.request(rankdataurl, {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                current_page: '' + pagesindexof
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    var formone = "";
                    for (var o in data.rank) {
                        if (typeof data['rank'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                            if (data['rank'][o]['nickname'].length > 5) {
                                data['rank'][o]['nickname'] = data['rank'][o]['nickname'].substr(0, 4) + "*";
                            }
                            var i = parseInt(o, 10);
                            formone += "<li id='addli'><div class='yst-top4'><div class='round' id='yst_rank_count'>" + (i + (pagesindexof - 1) * 10 + 1) + "</div><img src='" + data['rank'][o]['avatar'] + "' class='t4img'><span class='s41' id='wx_nickname'>" + data['rank'][o]['nickname'] + "</span><span class='s42' id='you_score'>" + data['rank'][o]['score'] + "</span><div class='wire1'></div></div></li>";
                        }
                    }
                    var more_containter = document.createElement('div');
                    more_containter.innerHTML = formone;
                    var ele = document.getElementById('yst-rank-container1');
                    ele.appendChild(more_containter);
                    ystpage_index++; // 页数增加
                } else {
                    alert('已经到底，没有更多了。');
                }
            },
            failure: function() {
                alert("网络异常！");
            }
        });
    };
    //排行榜返回功能 20150808 ggb
    yisutui.rankback = function() {
        ystpage_index = 2;
        ystpage_friend_index = 2;
        ystrank_flag = "more";
        // var yisutui_=document.body;
        // yisutui_.removeChild(yisutui_.childNodes[0]);
        document.getElementById('itemrank').style.display = "none";
        document.getElementById('friendsrank').style.display = "none";
    };
    // 重置数据
    yisutui.setData = function() {
        document.getElementById('yinpai').src = "";
        document.getElementById('yinpai').style.display = "none";
        document.getElementById('yst-wxtop2').src = "";
        document.getElementById('yst-wxtop2').style.display = "none";
        document.getElementById('yst-wxtop2-nickname').innerText = "";
        document.getElementById('yst-wxtop2-rank').innerText = "";
        document.getElementById('tongpai').src = "";
        document.getElementById('tongpai').style.display = "none";
        document.getElementById('yst-wxtop3').src = "";
        document.getElementById('yst-wxtop3').style.display = "none";
        document.getElementById('yst-wxtop3-nickname').innerText = "";
        document.getElementById('yst-wxtop3-rank').innerText = "";
        document.getElementById('yst-rank-container').innerHTML = "";

    };
    // 好友排行榜 20151205 by fg
    yisutui.friendsrank = function() {
        var yisutui_ = document.getElementById('friendsrank');
        if (!yisutui_) {
            var yisutui__div = document.createElement('div');
            var yisutui__css = document.createElement('style');
            yisutui__div.id = 'friendsrank';
            var yst_top1 = domain + "/API/img/jinpai.png";
            var yst_top2 = domain + "/API/img/yinpai.png";
            var yst_top3 = domain + "/API/img/tongpai.png";
            var yst_morerank = domain + "/API/img/xiala.png";
            var yst_back = domain + "/API/img/f_rank_bg.png";
            var yst_goback = domain + "/API/img/fanhui.png";
            var yst_rule_menu = "/API/img/all_rank.png";
            var yst_exch_prize = domain + "/API/img/duijiang.png";
            yisutui__div.innerHTML = "<div class='rankcontainer'><div class='yst-rank-box'><img src='" + yst_back + "' class='yst_back' id='yst-rank-bg' style='-webkit-user-select: none;user-select: none;'><div class='yst-rank1'><div class='yst-rank-top3'><ul style='margin:0;padding:0;overflow:auto;'><li class='yst-top2'><img class='t2img' id='fryst-wxtop2' style='-webkit-user-select: none;user-select: none;'><img class='yinpai' id='yinpai' style='-webkit-user-select: none;user-select: none;'><div class='s21' id='fryst-wxtop2-nickname'></div><div class='s22' id='fryst-wxtop2-rank'></div></li><li class='yst-top1'><img class='t1img' id='fryst-wxtop1' style='-webkit-user-select: none;user-select: none;'><img src='" + yst_top1 + "' class='jinpai'><div class='s11' id='fryst-wxtop1-nickname' style='-webkit-user-select: none;user-select: none;'></div><div class='s12' id='fryst-wxtop1-rank'></div></li><li class='yst-top3'><img class='t3img' id='fryst-wxtop3' style='-webkit-user-select: none;user-select: none;'><img class='tongpai' id='tongpai' style='-webkit-user-select: none;user-select: none;'><div class='s31' id='fryst-wxtop3-nickname'></div><div class='s32' id='fryst-wxtop3-rank'></div></li></ul><div class='xian'></div></div><div class='yst-rank-con'><div id='lfg-style'></div><ul class='rank-container' id='yst-rank-container2'></ul><img src='" + yst_morerank + "' class='xiala' id='f-yst-onload' style='-webkit-user-select: none;user-select: none;' ontouchstart=yisutui.fonload()></div><div><img src='" + yst_goback + "' class='fanhui' style='-webkit-user-select: none;user-select: none;'ontouchstart='yisutui.rankback()' id='yst-fanhui'><img src='" + yst_rule_menu + "' class='yst-all-rank' id='yst-all-rank' style='-webkit-user-select: none;user-select: none;' ontouchstart='yisutui.itemrank()'></div></div><img src='" + yst_exch_prize + "' id='yst-duijiang' class='duijiang' style='-webkit-user-select: none;user-select: none;' ontouchstart='yisutui.rankrule()'></div></div>";
            yisutui__css.innerHTML = ".rankcontainer{width:100%; height:100%; z-index:10002;position: fixed; top: 0; left: 0;}.yst_back{width: 82%;height: 86%;position: fixed;left: 9%;top: 4%;}.yst-rank-box{width:100%;height:100%;position:fixed;left:0;top:0;background:rgba(0,0,0,0.6);z-index:101}.yst-rank1{width: 80%;height: 90%;position: fixed;left: 10%;top: 4%;overflow: hidden;}.yst-rank-con{width:100%;height:55%;overflow-y:auto;color:#fff;position:relative;top:7%}.yst-rank-top3{width: 100%;height: 26%;position: relative;top: 7%;}.yst-top1{list-style-type:none;width:33.333%;float:left;position:relative;margin-top:7.5%;}.yst-top2{list-style-type:none;width:33.333%;float:left;position:relative;margin-top:11.5%;}.yst-top3{list-style-type:none;width:33.333%;float:left;position:relative;margin-top:11.5%;}.t1img{border-radius:100%;width:64%;margin-left:18%;position:relative}.jinpai{width:15%;position:relative;margin-top:2%;margin-left:42.5%;}.s11{color:#fff;font-size:0.7rem;position:relative;width: 100%;text-align: center;-webkit-user-select:none;user-select:none;}.s12{color:#fff;font-size: 1rem;position: relative;width: 100%;text-align: center;-webkit-user-select:none;user-select:none;}.t2img{border-radius:100%;width:52%;margin-left:24%;position:relative}.yinpai{width:15%;position:relative;margin-top:2%;margin-left:42.5%;}.s21{color:#fff;font-size:0.7rem;position:relative;width: 100%;text-align: center;-webkit-user-select:none;user-select:none;}.s22{color:#fff;font-size: 1rem;position: relative;width: 100%;text-align: center;-webkit-user-select:none;user-select:none;}.t3img{border-radius:100%;width:52%;margin-left:24%;position:relative;}.tongpai{width:15%;position:relative;margin-top:2%;margin-left:42.5%;}.s31{color:#fff;font-size:0.7rem;position:relative;width: 100%;text-align: center;-webkit-user-select: none;user-select: none;}.s32{color:#fff;font-size:1rem;position: relative;width: 100%;text-align: center;-webkit-user-select: none;user-select: none;}.xian{width:84%;border-bottom:1px solid #fff;margin: auto;}.paiming4{width:7%;top:23%;left:5%;position:absolute}.xian1{position:absolute;top:95%;left:3%;width:87.5%;border-bottom:2px solid #fff}.xiala{width:8%;position:relative;margin-left:45.5%;display:none;margin-bottom: 6%;margin-top:3%;}.fanhui{position:fixed;top:83%;left:15%;width:30%}.yst-all-rank{position:fixed;top:83%;left:54%;width:30%}.wire{position:absolute;top:97%;left:7%;width:84%;border-bottom:1px solid #7e7b7b}.yst-top4{position:relative;overflow:auto;padding-top: 2%;}.round{width:28px;height:28px;border:1px solid #fff;border-radius:100%;text-align:center;font-size:17px;line-height:28px;float:left;-webkit-user-select: none;user-select: none;}.t4img{border-radius:100%;width:13%;margin-left:3%;margin-bottom:1%;float:left;}.s41{font-size:0.7rem;float:left;margin-left:2%;color:#fff;-webkit-user-select: none;user-select: none;}.s42{color: #fff;font-size: 1rem;float: right;-webkit-user-select: none;user-select: none;}.wire1{border-bottom:1px solid #7e7b7b;width: 100%;float: left;}.rank-container{margin:0;padding:0}.rank-container li{list-style-type:none;margin:auto;width:84%}.drop-down{width:8%;position:relative;margin-left:46%;margin-top:2%}.duijiang{position: fixed;width: 8%;top: 30%;}";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui__div, first);
            document.head.appendChild(yisutui__css);
            if (marketing != "3") {
                document.getElementById('yst-duijiang').style.display = "none";
            }
            Ajax.request("/g/getfriendrank", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    current_page: '1'
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (parseInt(data.picset) == 1) { //有设置总排行榜的相关图片
                        var frankbg = domain + "/files/images/" + data.itempic.frankbg;
                        var rankback = domain + "/files/images/" + data.itempic.rankback;
                        var allrank = domain + "/files/images/" + data.itempic.allrank;
                    } else { //没设置
                        var frankbg = domain + "/files/images/frankbg.png";
                        var rankback = domain + "/files/images/rankback.png";
                        var allrank = domain + "/files/images/allrank.png";
                    }
                    document.getElementById('yst-rank-bg').src = frankbg;
                    document.getElementById('yst-fanhui').src = rankback;
                    document.getElementById('yst-all-rank').src = allrank;
                    if (data.code == "1") {
                        // var formone="<div class='formone22'>";
                        var formone = "";
                        for (var o in data.rank) {
                            if (typeof data['rank'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                                if (data['rank'][o]['nickname'].length > 5) {
                                    data['rank'][o]['nickname'] = data['rank'][o]['nickname'].substr(0, 4) + "*";
                                }
                                var i = parseInt(o, 10);
                                if (i >= 3) {
                                    formone += "<li id='addli'><div class='yst-top4'><div class='round' id='yst_rank_count' style='-webkit-user-select: none;user-select: none;'>" + (i + 1) + "</div><img src='" + data['rank'][o]['avatar'] + "' class='t4img' style='-webkit-user-select: none;user-select: none;'><span class='s41' id='wx_nickname' style='-webkit-user-select: none;user-select: none;'>" + data['rank'][o]['nickname'] + "</span><span class='s42' id='you_score' style='-webkit-user-select: none;user-select: none;'>" + data['rank'][o]['score'] + "</span><div class='wire1' style='-webkit-user-select: none;user-select: none;'></div></div></li>";
                                } else {
                                    switch (i) {
                                        case 0:
                                            document.getElementById('fryst-wxtop1').src = data['rank'][o]['avatar'];
                                            document.getElementById('fryst-wxtop1-nickname').innerText = data['rank'][o]['nickname'];
                                            document.getElementById('fryst-wxtop1-rank').innerText = data['rank'][o]['score'];
                                            break;
                                        case 1:
                                            document.getElementById('yinpai').src = yst_top2;
                                            document.getElementById('fryst-wxtop2').src = data['rank'][o]['avatar'];
                                            document.getElementById('fryst-wxtop2-nickname').innerText = data['rank'][o]['nickname'];
                                            document.getElementById('fryst-wxtop2-rank').innerText = data['rank'][o]['score'];
                                            break;
                                        case 2:
                                            document.getElementById('tongpai').src = yst_top3;
                                            document.getElementById('fryst-wxtop3').src = data['rank'][o]['avatar'];
                                            document.getElementById('fryst-wxtop3-nickname').innerText = data['rank'][o]['nickname'];
                                            document.getElementById('fryst-wxtop3-rank').innerText = data['rank'][o]['score'];
                                            break;
                                    }
                                }
                                if (i == 9) { // 点击加载更多现实图标
                                    document.getElementById('f-yst-onload').style.display = "block";
                                }
                            }
                        }
                        document.getElementById('yst-rank-container2').innerHTML = formone;

                        setTimeout(function() {
                            if (document.getElementById('addli') != null) {
                                var item_H = document.getElementById('addli').offsetHeight;
                                var str = "<style>.round{margin-top:1.5%;font-size:1.5rem;}.s42,.s41{line-height:3.4rem;font-size: 1.4rem;}.t4img{margin-top:0.3%;}</style>";
                                document.getElementById('lfg-style').innerHTML = str;
                            }
                        }, 80);
                    } else {
                        alert('抱歉，网络不稳定，请重玩游戏获取成绩。');
                    }
                },
                failure: function() {
                    console.log("网络异常！");
                }
            });
            document.getElementById('friendsrank').style.display = "none";
        } else {
            //显示好友排行，先隐藏总排行
            var yisutui_itemrank = document.getElementById('itemrank');
            if (yisutui_itemrank) {
                document.getElementById('itemrank').style.display = "none";
            }
            document.getElementById('friendsrank').style.display = "block";
        }

    };
    // 数据显示
    yisutui.fonload = function() {
        var pagesindexof = ystpage_friend_index;
        var rankdataurl = "/g/getfriendrank";
        Ajax.request(rankdataurl, {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                current_page: '' + pagesindexof
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    var formone = "";
                    for (var o in data.rank) {
                        if (typeof data['rank'][o] == 'object') { //封装的ajax最后会返回一个函数，需排除
                            if (data['rank'][o]['nickname'].length > 5) {
                                data['rank'][o]['nickname'] = data['rank'][o]['nickname'].substr(0, 4) + "*";
                            }
                            var i = parseInt(o, 10);
                            formone += "<li id='addli'><div class='yst-top4'><div class='round' id='yst_rank_count'>" + (i + (pagesindexof - 1) * 10 + 1) + "</div><img src='" + data['rank'][o]['avatar'] + "' class='t4img'><span class='s41' id='wx_nickname'>" + data['rank'][o]['nickname'] + "</span><span class='s42' id='you_score'>" + data['rank'][o]['score'] + "</span><div class='wire1'></div></div></li>";
                        }
                    }
                    // var ele = document.getElementById('yst-rank-container').innerHTML = formone;
                    var more_containter = document.createElement('div');
                    more_containter.innerHTML = formone;
                    var ele = document.getElementById('yst-rank-container2');
                    ele.appendChild(more_containter);
                    ystpage_friend_index++; // 页数增加
                } else {
                    alert('已经到底，没有更多了。');
                }
            },
            failure: function() {
                alert("网络异常！");
            }
        });
    };
    //排行榜活动规则 20150808 ggb
    yisutui.rankrule = function() {
            var yisutui_start = document.getElementById('rankrule');
            if (!yisutui_start) {
                var yisutui_start_div = document.createElement('div');
                var yisutui_start_css = document.createElement('style');
                yisutui_start_div.id = 'rankrule';
                var left_icon = domain + "/files/images/" + rankruleleft;
                var right_icon = domain + "/files/images/" + rankruleright;
                yisutui_start_div.innerHTML = "<div class='rankrulecontainer'><div class='backgroundImg'></div><div class='yst_rulebg'><img src='" + domain + "/files/images/" + rankruleclose + "' class='yst_rule_close' ontouchstart='yisutui.closerules()'></div><div class='change_describe'>兑奖描述</div><div class='tiptext' id='tiptext'></div><div class='prize_title'>奖品</div><div class='yst_rule_con' id='yst_rule_con'><div id='yst_rule_contenter'></div><div class='yst_rule_prize'><div class='yst_rule_left' id='yst_rule_left'><img src='" + left_icon + "' class='left-icon' id=''></div><div class='yst_rule_center'><ul class='yst_rule_imgul' id='yst_rule_imgul'><img id='prize_img'><img class='roundBg' src='" + domain + "/files/images/" + rankruleshadow + "'><div id='prize_name'></div></ul></div><div class='yst_rule_right' id='yst_rule_right'><img src='" + right_icon + "' class='right-icon' id=''></div><div style='clear:both;'></div></div></div><div class='yst_rule_ending'><img src='" + domain + "/files/images/" + rankruleback + "' ontouchstart='yisutui.closerules()'></div></div>";
                yisutui_start_css.innerHTML = "body{margin:0; padding: 0; border:0;} .right-icon{width: 47%;}.left-icon{width: 47%;}.rankrulecontainer{width:100%;height:100%; z-index:10003; position: absolute; top: 0; left: 0; overflow: scroll;} .yst_rulebg{width:100%;margin:0; border:0; position: relative;} .yst_rule_bg{width:100%;margin:0; border:0;} .yst_rule_close{position:absolute;width:12%;top: 0%; left:88%} .yst_rule_con{color: #FFF;margin-top:3%;} .yst_rule_contenter{margin: 0; text-align: center;padding: 0; font-size: 1.1rem; clear: both;position:relative;} .yst_rule_contenter1{padding-top: 6%;} .yst_rule_contenter li{list-style-type: none;padding-top: 3%; text-align: center;} .yst_rule_prize{width: 80%;margin-left: 10%; height: 30%; margin-top: 5%;} .yst_rule_left{position:relative; float: left; margin-top: 10%; width: 15%; text-align: center; font-weight: bold; font-size: 4rem;} .yst_rule_center{float: left; width: 70%; text-align: center; overflow: hidden; } .yst_rule_right{position:relative;float: left; margin-top: 10%; width: 15%;text-align: center; font-weight: bold; font-size: 4rem;} .yst_rule_imgul{list-style: none; padding:0; margin: 0; width: 100%; position: relative;} .yst_rule_imgul li{float: left; width: 10%} .yst_rule_imgul li img{border-radius: 100%; width: 70%;} .yst_rule_ending{position:relative;height: 15%;} #prize_img{width: 48%;border-radius: 100%;margin-top: 1%}.tiptext{position:relative;width:60%;left:20%;top:5%;color:#ffffff;font-size: 1.4rem;height:20%;border-bottom:1px dashed #fff;} .roundBg{position: absolute;width: 48%;height: 80.75%;top:2%;left: 26.3%;}#prize_name{position:relative;width:100%;height:50px;left:0;color:#fff;font-size:1.5rem;margin-top:-13%;z-index:10;} .yst_rule_ending img{width:28%;margin-left:37%;margin-top:8%;}.change_describe{position:relative;width:100%;text-align:center;font-size:2rem;color:#fff;margin-top:72%;} .prize_title{position:relative;width:100%;text-align:center;color:#fff;margin-top:13%;font-size:2rem;} .backgroundImg{width:100%;height:140%;position:absolute;background-image:url(" + domain + "/files/images/" + rankrulebg + ");background-size: cover;}";
                var first = document.body.firstChild;

                document.body.insertBefore(yisutui_start_div, first);
                document.head.appendChild(yisutui_start_css);
                document.getElementById('yst_rule_imgul').style.width = document.documentElement.clientWidth * 0.6 + "px";
                // document.getElementById('yst_rule_imgul').style.height = document.documentElement.clientHeight*0.17+"px";

                Ajax.request("/g/getrankrule", {
                    async: true,
                    method: "POST",
                    encode: "UTF-8",
                    data: {
                        itemid: itemid
                    },
                    success: function(xhr) {
                        var data = JSON.parse(xhr.responseText);
                        if (data.code == "1") {
                            var formone = "<ul class='yst_rule_contenter'>";
                            var imgone = [];
                            var prizename = [];
                            // console.log(data['itemprize']);
                            for (var o in data.itemprize) {
                                if (!isNaN(parseInt(o))) {
                                    var prize_num = data['itemprize'][o]['endrank'] - data['itemprize'][o]['startrank'] + 1;
                                    formone = formone + "<li class='yst_rule_contenter1'>" + data['itemprize'][o]['awardname'] + ": " + prize_num + "名, 奖" + data['itemprize'][o]['prizename'] + "</li>";
                                    imgone.push(domain + '/files/images/' + data['itemprize'][o]['prizepic']);
                                    prizename.push(data['itemprize'][o]['awardname'].substring(0, 3));
                                }
                            }
                            formone = formone + "</ul>";
                            if (data.iteminfo.prizetip.length > 95) {
                                data.iteminfo.prizetip = data.iteminfo.prizetip.substring(0, 95) + "...";
                            }
                            document.getElementById('tiptext').innerText = data.iteminfo.prizetip;
                            var tipcontainer = document.getElementById('yst_rule_contenter');
                            var tipimage = document.getElementById('yst_rule_imgul');
                            yisutui.append(tipcontainer, formone);
                            var img_index = 0;
                            document.getElementById('prize_img').src = imgone[img_index];
                            document.getElementById('prize_name').innerHTML = prizename[img_index];

                            document.getElementById('yst_rule_left').ontouchstart = function() {
                                if (img_index > 0) {
                                    img_index--;
                                } else {
                                    img_index = imgone.length - 1;
                                }
                                document.getElementById('prize_img').src = imgone[img_index];
                                document.getElementById('prize_name').innerHTML = prizename[img_index];

                            }
                            document.getElementById('yst_rule_right').ontouchstart = function() {
                                if (img_index < imgone.length - 1) {
                                    img_index++;
                                } else {
                                    img_index = 0;
                                }
                                document.getElementById('prize_img').src = imgone[img_index];
                                document.getElementById('prize_name').innerHTML = prizename[img_index];

                            }
                        } else {
                            alert('获取表单数据出错！');
                        }
                    },
                    failure: function() {
                        console.log("网络异常！");
                    }
                });
                document.getElementById('rankrule').style.display = "none";
            } else {
                document.getElementById('rankrule').style.display = "block";
            }
        }


    yisutui.ctypeform=function(){
        Ajax.request("/g/drawtype",{
            async:true,
            method:"POST",
            encode:"UTF-8",
            data:{
                itemid:itemid
            },
            success:function(xhr){
                var data = JSON.parse(xhr.responseText);
                if(data.status=="1"){
                    yisutui.getcoupon();
                }
                if(data.status=="2"){
                    yisutui.cwechatform();
                }
            },
             failure: function() {
                alert("网络异常！");
            }
        });
    }
    //游戏优惠券抽奖 20150811 ggb
    yisutui.getcoupon = function() {
        Ajax.request("/g/get_coupon", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                score: gamescore
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "3") {

                    var yisutui_start = document.getElementById('coupon');

                    if (!yisutui_start) {
                        var yisutui_start_div = document.createElement('div');
                        var yisutui_start_css = document.createElement('style');
                        yisutui_start_div.id = 'coupon';


                        yisutui_start_div.innerHTML = "<div class='couponcontainer'><div class='yst_mycoupons_bg'><img src='" + domain + "/API/img/coupons.png' class='yst_conpons'><div class='yst_coupons_prize'><p class='yst_coupons_p1'>" + data.data.prizetip + "</p><p class='yst_coupons_p2'>获得了<span>" + data.data.awardname + "</span>一张</p><p class='yst_coupons_p3'>券号为：<span>" + data.couponnum + "</span></p><p class='yst_coupons_p4'>注：请到“我的优惠券”里面查看</p></div><img src='" + domain + "/API/img/coupon_close.png' class='yst_coupons_close' ontouchstart='yisutui.couponback()'></div></div>";
                        yisutui_start_css.innerHTML = ".couponcontainer {z-index:10008;position: fixed; top: 0; left: 0; width: 100%; height: 100%;} .yst_mycoupons_bg{width: 100%; height: 100%; background-color: rgba(0,0,0,.6); position: fixed;top: 0; left: 0;} .yst_conpons{position: fixed;top: 23%; left: 15%; width: 70%;} .yst_coupons_prize{position: fixed;top: 23%;left: 15%; color: #696453;text-align: center; font-weight: 600; height: 36%; width: 70%;} .yst_coupons_prize span{color: #f40325;} .yst_coupons_prize p{margin-bottom: 0;font-size:1.5rem;} .yst_coupons_p1{margin-top: 18%;} .yst_coupons_p3{margin-top: 2%;} .yst_coupons_p4{font-size: 0.8rem; margin-top: 10%} .yst_coupons_close{position: fixed;top: 21%;left: 80%;width: 8%;}"
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui_start_div, first);
                        document.head.appendChild(yisutui_start_css);
                    }
                } else if (data.code == "1") {
                    alert(data.msg);
                } else {
                    alert(data.msg);
                }
            },
            failure: function() {
                alert("保存异常！");
            }
        });
        var coupshow = document.getElementById('coupshow');
        if (coupshow) { //移除我的优惠券页面
            document.getElementById('coupshow').parentNode.removeChild(document.getElementById('coupshow'));
        }
        var getcoupon = document.getElementById('getcoupon');
        //移除监听事件
        if (getcoupon.removeEventListener) { // // 所有浏览器，除了 IE 8 及更早IE版本
            getcoupon.removeEventListener("touchstart", yisutui.ctypeform, false);
        } else if (getcoupon.detachEvent) { // IE 8 及更早IE版本
            getcoupon.detachEvent("touchstart", yisutui.ctypeform);
        }
        //添加监听事件
        getcoupon.addEventListener("touchstart", yisutui.moreclicktip, false);
    };
    //优惠券公众号中接口 20160317 syq
    yisutui.cwechatform = function() {
        var isbarrage=document.getElementById('yst-barrage-mask');
        if(isbarrage){
            isbarrage.style.display="none";
        }
        var yisutui_start = document.getElementById('redcommend');
        if (!yisutui_start) {
            Ajax.request('/g/create_coupontoken', {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: { itemid: itemid, score: gamescore },
                success: function(xhr) {

                    var data = JSON.parse(xhr.responseText);
                    if(data.status==2){
                        var tip=data.tip;
                        if(tip == ""){
                            tip="得分不足";
                        }
                        alert(tip);
                        return;
                    }
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'redcommend';
                    yisutui__div.innerHTML = "<div class='yst-get-passwordred'><div class='yst-passwordred-top'><div  id='yst-passwordred-text' class='yst-passwordred-text'>" + data.token + "</div></div><div class='yst-passwordred-qr'><img src='" + data.qrcodeurl + "'></div><div class='yst-passwordred-bottom'><p>领取说明:</p><div class='yst-receive-con'>" + data.gettip + "</div></div><img src='" + domain + "/files/images/tokenback.png' class='redcom-back' ontouchstart='yisutui.rwechatclose()'></div>";
                    yisutui__css.innerHTML = "html{font-size:62.5%;}a, p, span, ul, ol, li, td {-webkit-tap-highlight-color: rgba(0, 0, 0, 0);padding: 0;margin: 0;list-style-type: none;text-decoration: none;}body{background: #fff;margin: 0;}.yst-get-passwordred{width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:99999;background-color:#fff}.yst-passwordred-top{width: 100%;height: 30%;text-align: center;background:url(/API/img/wordbg.png);background-size: 100% 100%;position:relative}.yst-passwordred-text{background-color:#fff;line-height:30px;width: 41%;height: 30px;outline: none;border: 0;border-radius: 12px;font-size: 1.4rem;text-align: center;padding: 0.5% 3% 0;color: #666;display: inline-block;font-weight: bold;position:absolute;top:41%;left:25%}.yst-passwordred-btn{border: 0;height: 100%;width: 25%;border-radius: 10px;background:yellow;color:red;margin-left:1%;outline:none;}.yst-passwordred-qr{text-align:center;margin-top:8%;height:30%;padding-bottom:8%;width:70%;margin-left:15%;border-bottom:1px dashed #fe514a;}.yst-passwordred-qr img{height:100%;}.yst-passwordred-bottom{margin-top:8%;width:100%;height:15%;}.yst-passwordred-bottom p{margin-left:10%; width:80%; font-size:1.6rem;color:#000;font-weight: bold;}.redcom-back{width: 40%;margin: 0% 30% 0px;position:fixed;bottom:5%}.yst-receive-con{width: 80%;margin-left: 10%;margin-top: 5px;font-size: 1.3rem;text-indent:2em;}";
                    var first = document.body.firstChild;
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            });
        }else{
           // var gamegetprize=document.getElementById('gamegetprize');
           //  gamegetprize.addEventListener("touchstart", yisutui.moreclicktip, false); 
           alert("亲~每次游戏结束后，只能领取一次口令");
        }

        
    }
    //领取微信红包 20151222 ggb
    yisutui.getmred = function() {
        Ajax.request("/g/getrankkey", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    mgamescore = enmimi(gamescore, 'ENCODE', data.key);
                    Ajax.request("/g/getmred", {
                        async: true,
                        method: "POST",
                        encode: "UTF-8",
                        data: {
                            itemid: itemid,
                            score: mgamescore,
                            keyid: data.keyid
                        },
                        success: function(xhr) {
                            var data = JSON.parse(xhr.responseText);
                            if (data.code == "3") {

                                var yisutui_start = document.getElementById('mredpaper');

                                if (!yisutui_start) {
                                    var yisutui_start_div = document.createElement('div');
                                    var yisutui_start_css = document.createElement('style');
                                    yisutui_start_div.id = 'mredpaper';


                                    // yisutui_start_div.innerHTML="<div class='couponcontainer'><div class='yst_mycoupons_bg'><img src='"+domain+"/API/img/coupons.png' class='yst_conpons'><div class='yst_coupons_prize'><p class='yst_coupons_p1'>恭喜你在"+data.data.act_name+"中</p><p class='yst_coupons_p2'>获得了<span>"+data.data.send_name+"发放的</span></p><p class='yst_coupons_p3'>微信红包<span>"+data.data.total_amount/100+"元</span></p><p class='yst_coupons_p4'>注：请到“微信”里面查看</p></div><img src='"+domain+"/API/img/coupon_close.png' class='yst_coupons_close' ontouchstart='yisutui.mredback()'></div></div>";
                                    // yisutui_start_css.innerHTML=".couponcontainer {z-index:10008;position: fixed; top: 0; left: 0; width: 100%; height: 100%;} .yst_mycoupons_bg{width: 100%; height: 100%; background-color: rgba(0,0,0,.6); position: fixed;top: 0; left: 0;} .yst_conpons{position: fixed;top: 23%; left: 15%; width: 70%;} .yst_coupons_prize{position: fixed;top: 23%;left: 15%; color: #696453;text-align: center; font-weight: 600; height: 36%; width: 70%;} .yst_coupons_prize span{color: #f40325;} .yst_coupons_prize p{margin-bottom: 0;font-size:1.5rem;} .yst_coupons_p1{margin-top: 18%;} .yst_coupons_p3{margin-top: 2%;} .yst_coupons_p4{font-size: 0.8rem; margin-top: 10%} .yst_coupons_close{position: fixed;top: 21%;left: 80%;width: 8%;}";

                                    yisutui_start_div.innerHTML = "<div class='couponcontainer'><div class='receive'><div class='receive-content'><p class='receive-content-p1'>恭喜您！</p><p class='receive-content-p2'>在<span>" + data.data.act_name + "</span>中，获得了<span>" + data.data.send_name + "</span>发放的微信红包</p><div class='receive-content-p3'><img src='" + domain + "/API/img/moneyIcon.png'>" + data.data.total_amount / 100 + "元</div><p class='receive-content-p4'>注：请到“微信”里面查看</p><img src='" + domain + "/API/img/OK.png'class='OKbtn' ontouchstart='yisutui.mredback()'></div></div></div>";
                                    yisutui_start_css.innerHTML = ".couponcontainer {z-index:10008;position: fixed; top: 0; left: 0; width: 100%; height: 100%;background: rgba(0,0,0,0.8);} .receive { position: absolute; width: 54%; height: 54%; margin-top: 20%; margin-left: 23%; background-image: url(" + domain + "/API/img/redPacket.png); background-size: 100% 100%; } .receive-content { position: relative; top: 34%; } .receive-content-p1 { color: #ffd600; font-size: 1.4rem; width: 80%; margin: 0 auto 0; text-align: center; } .receive-content-p2 { color: #fff; text-align: left; font-size: 0.7rem; width: 80%; margin: 0 auto 0; margin-top: 10px; } .receive-content-p3 { height: 20px; line-height: 20px; width: 80%; margin: 0 auto; color: #ffff33; font-weight: bold; width: 80%; margin: 0 auto 0; margin-top: 10px; } .receive-content-p3 img { height: 100%; float: left; margin-left: 30%; } .OKbtn { margin-left: 15%; margin-top: 20px; width: 70%; } .receive-content-p4 { color: #fff; text-align: left; font-size: 0.7rem; width: 80%; margin: 0 auto 0; margin-top: 10px; } @media all and (max-width:320px) { .receive-content-p2, .receive-content-p3, .receive-content-p4, .OKbtn { margin-top: 4px; } } .receive-content-p2 span { color: #ffd600; }";

                                    var first = document.body.firstChild;

                                    document.body.insertBefore(yisutui_start_div, first);
                                    document.head.appendChild(yisutui_start_css);
                                }
                                var getmyred = document.getElementById('getmyred');
                                if (getmyred) { //移除我的红包页面
                                    document.getElementById('getmyred').parentNode.removeChild(document.getElementById('getmyred'));
                                }
                            } else if (data.code == "1") {
                                alert(data.msg);
                            } else {
                                alert(data.msg);
                            }
                        },
                        failure: function() {
                            alert("保存异常！");
                        }
                    });
                }else{
                    console.log("get key faile");
                }
            },
            failure: function() {
                console.log("网络异常！");
            }
        });


        
        var getmred = document.getElementById('getmred');
        //移除监听事件
        if (getmred.removeEventListener) { // // 所有浏览器，除了 IE 8 及更早IE版本
            getmred.removeEventListener("touchstart", yisutui.getmred, false);
        } else if (getmred.detachEvent) { // IE 8 及更早IE版本
            getmred.detachEvent("touchstart", yisutui.getmred);
        }
        //添加监听事件
        getmred.addEventListener("touchstart", yisutui.moreclicktip, false);
    };
    //访问一次自动增加浏览数 20150811 ggb
    yisutui.addhit = function() {
        Ajax.request("/g/addhit", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid,
                isact:0
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                console.log(data.msg);
                console.log(data.ipmsg);
            },
            failure: function() {
                console.log("网络异常！");
            }
        });
    }

    //游戏结束后分享 20150817 ggb
    yisutui.successshare = function(score) {
        Ajax.request(domain + '/wxshare/sample.php?url=' + window.location.href, {
            async: true,
            method: "GET",
            encode: "UTF-8",
            success: function(xhr) {
                var response = JSON.parse(xhr.responseText);
                console.log(response);
                var appid = response.appId;
                var timestamp = response.timestamp;
                var nonceStr = response.nonceStr;
                var signature = response.signature;
                yisutui.successshareFriends(appid, timestamp, nonceStr, signature, score);
            },
            failure: function() {
                console.log('failure');
            }
        });
    }

    yisutui.successshareFriends = function(appid, timestamp, nonceStr, signature, score) {
            wx.config({
                debug: false,
                appId: "" + appid,
                timestamp: '' + timestamp,
                nonceStr: '' + nonceStr,
                signature: '' + signature,
                jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
            });
            //获取微信分享的相关设置信息 20150811 ggb
            Ajax.request("/g/getsuccessshare", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid,
                    score: score
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (data.status == 1) {
                        var info = data.title;
                        var desc = data.desc;
                        var shareimg = data.shareimg;
                        if (parseInt(data.ssmode) == 1&&data.failshareurl!="http://") {
                            shareurl = data.successshareurl;
                        } else {
                            shareurl = domain + '/g/w/' + itemid + '?fopenid=' + data.openid;
                        }
                    } else {
                        var info = "你也可以免费制作微信营销游戏，快来试试！";
                        var desc = "在电脑上访问www.yisutui.com，马上免费制作营销游戏！";
                        var shareimg = "http://www.xxuc.cn/lfgimg/exoshare.png";
                        shareurl = domain + '/g/w/' + itemid + '?fopenid=' + data.openid;
                    }
                    wx.ready(function() {
                        wx.onMenuShareTimeline({
                            title: '' + desc,
                            link: shareurl,
                            imgUrl: '' + shareimg,
                            success: function() {
                                Ajax.request("/g/shareadd", {
                                    async: true,
                                    method: "POST",
                                    encode: "UTF-8",
                                    data: {
                                        itemid: itemid,
                                        isact:0
                                    },
                                    success: function(xhr) {
                                        var data = JSON.parse(xhr.responseText);
                                        if (data.status == 1) {
                                            console.log("分享成功！");
                                        } else {
                                            console.log("分享失败！");
                                        }
                                    },
                                    failure: function() {
                                        console.log("网络异常！");
                                    }
                                });
                            }
                        });
                        wx.onMenuShareAppMessage({
                            title: '' + info,
                            desc: '' + desc,
                            link: shareurl,
                            imgUrl: '' + shareimg,
                            type: 'link',
                            success: function() {
                                Ajax.request("/g/shareadd", {
                                    async: true,
                                    method: "POST",
                                    encode: "UTF-8",
                                    data: {
                                        itemid: itemid,
                                        isact:0
                                    },
                                    success: function(xhr) {
                                        var data = JSON.parse(xhr.responseText);
                                        if (data.status == 1) {
                                            console.log("分享成功！");
                                        } else {
                                            console.log("分享失败！");
                                        }
                                    },
                                    failure: function() {
                                        console.log("网络异常！");
                                    }
                                });
                            }
                        });
                    });
                },
                failure: function() {
                    var info = "你也可以免费制作微信营销游戏，快来试试！";
                    var desc = "在电脑上访问www.yisutui.com，马上免费制作营销游戏！";
                    var shareimg = "http://www.xxuc.cn/lfgimg/exoshare.png";
                    wx.ready(function() {
                        wx.onMenuShareTimeline({
                            title: '' + info,
                            link: '' + window.location.href,
                            imgUrl: '' + shareimg
                        });
                        wx.onMenuShareAppMessage({
                            title: '' + info,
                            desc: '' + desc,
                            link: '' + window.location.href,
                            imgUrl: '' + shareimg,
                            type: 'link'
                        });
                    });
                }
            });
        }
        //获得优惠券后返回 20150813 ggb
    yisutui.couponback = function() {
            var yisutui_ = document.body;
            yisutui_.removeChild(yisutui_.childNodes[0]);
            var coupshow = document.getElementById('coupshow');
            if (!coupshow) {
                yisutui.coupshow(); //预加载我的优惠券页面
            }
        }
        //领取微信红包后返回 20151222 ggb
    yisutui.mredback = function() {
            var yisutui_ = document.body;
            yisutui_.removeChild(yisutui_.childNodes[0]);
        }
        //提示抽奖次数用完 20150813 ggb
    yisutui.moreclicktip = function() {
            alert("亲~每次游戏结束后，只能抽奖1次，如需再抽奖，请重玩游戏获取抽奖机会！");
        }
        //排行榜活动规则关闭按钮
    yisutui.rankruleclose = function() {
        var yisutui_ = document.body;
        yisutui_.removeChild(yisutui_.childNodes[0]);
    }



    //优惠券悬浮块 20150827  lbb
    yisutui.gameCoupons = function() {
        var yisutui_start = document.getElementById('gamecoup');
        if (!yisutui_start) {
            var yisutui_start_div = document.createElement('div');
            var yisutui_start_css = document.createElement('style');
            yisutui_start_css.innerHTML = ".yst_coupon_gift{position: fixed;top: 30%;left: 1%;width: 9%;z-index: 10000;}"
            var first = document.body.firstChild;

            document.head.appendChild(yisutui_start_css);
        }
    };

    //优惠券页面显示   20150828    lbb
    yisutui.coupshow = function() {
        var yisutui_start = document.getElementById('coupshow');
        if (!yisutui_start) {
            var yisutui_start_div = document.createElement('div');
            var yisutui_start_css = document.createElement('style');
            yisutui_start_div.id = 'coupshow';

            yisutui_start_div.innerHTML = "<div class='coupcontainer'><img src='" + domain + "/files/images/" + mycoupontext + "' class='yst_coupon_mycoupon'><div class='yst_coupon_bg' id='yst_coupon_bg'><img src='" + domain + "/files/images/" + mycouponbg + "' class='yst_coupon_bgimg'><div class='yst_coupon_namelist'><div class='yst_coupon_con' id='coupon_addli'></div></div><img src='" + domain + "/files/images/" + mycouponclose + "' class='yst_coupon_close' ontouchstart='yisutui.coupclose()'></div></div>";
            yisutui_start_css.innerHTML = ".coupcontainer{z-index: 9999; width: 80%; height: 80%; position: absolute; top: 10%; left: 10%;} .yst_coupon_mycoupon{position: fixed;top: 31%; left: 2%; height: 21%;} .yst_coupon_bg{width: 75%;height: 90%; position: fixed; left: 15%; top: 5%;} .yst_coupon_bgimg{width: 100%; height: 100%;} .yst_coupon_namelist{width: 75%; height: 70%; position: fixed; top: 24%;} .yst_coupon_con{width: 100%; height: 90%; position: relative; top: 0%; overflow-y:auto; } .coupon_container{margin:0; margin-left:10%;padding: 0; color: #925206; font-weight: 600; font-size: 1.5rem;} .coupon_container li{list-style: none; display: block; height: 10%;margin-top:3%;} .yst_coupon_name{margin-top: 5%;} .yst_coupon_s1{margin-left: 6%;} .yst_coupon_s2{position: absolute;right: 18%;} .yst_coupon_close{position: fixed; top: 4%; left: 84%; width: 8%;} .coup{font-size: 1.2rem;color: white;width: 100%;margin-top: 6px;float:left;color:#925206;} .coup1{float: left;width:50%} .coup2{float: right;margin-right:0%;width:50%;text-align:center;}";

            var first = document.body.firstChild;

            document.body.insertBefore(yisutui_start_div, first);
            document.head.appendChild(yisutui_start_css);
            Ajax.request("/g/get_coupshow_list", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (data.code == "1") {
                        var coupon_name = "<ul class='coupon_container'>";
                        // console.log(data.coupon);
                        for (var o in data.coupon) {
                            if (!isNaN(parseInt(o))) {
                                if (data['coupon'][o]['awardname'].length > 7) {
                                    data['coupon'][o]['awardname'] = data['coupon'][o]['awardname'].substring(0, 7) + "*";
                                }
                                coupon_name = coupon_name + "<li class='coup1'>" + data['coupon'][o]['num'] + "</li><li class='coup2'>" + data['coupon'][o]['awardname'] + "</li>";
                            }
                        }
                        coupon_name = coupon_name + "</ul>";
                        var couponcontain = document.getElementById('coupon_addli');
                        yisutui.append(couponcontain, coupon_name);
                    }
                },
                failure: function() {
                    alert("数据异常！");
                }
            });
            document.getElementById('coupshow').style.display = "none";
        } else {
            document.getElementById('coupshow').style.display = "block";
        }

    };
    //版权漂浮块 20151124 ggb
    yisutui.ystspread = function() {
        Ajax.request("/g/isdellink", {
            async: false,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (parseInt(data.dellink) == 1 || parseInt(itemid) == 5053) {
                    console.log("去掉版权");
                } else if (parseInt(itemid) == 3643) {
                    var yisutui_ = document.getElementById('ystspreadfloat');
                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'ystspreadfloat';
                        yisutui__div.innerHTML = "<div class='ystspreadfloat'><div class='spreadleft'>技术支持》<a href='http://www.yisutui.com'>易速推</a></div><div class='spreadright' ontouchstart='yisutui.spreadclose()'>×</div>";
                        yisutui__css.innerHTML = ".ystspreadfloat {width: 56%;float: right;position: absolute;bottom: 0.7rem;right: 0px; background-color: rgba(60,60,61,0.5); color: #ffffff; height: 3rem; line-height: 3rem;border-radius: 1.5rem;font-size: 1.4rem;z-index:9996;} .spreadleft {position:relative; width:85%;float: left; text-align:center;} .spreadleft a {color: #09d5f3;font-weight: bold;text-decoration: none;} .spreadright {position:relative;width:15%;float:left;font-size: 2rem;height: 3rem;line-height: 3rem;font-weight: bolder;text-align:left;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                    }
                } else {
                    var yisutui_ = document.getElementById('ystspreadfloat');
                    if (!yisutui_) {
                        var yisutui__div = document.createElement('div');
                        var yisutui__css = document.createElement('style');
                        yisutui__div.id = 'ystspreadfloat';
                        yisutui__div.innerHTML = "<div class='ystspreadfloat'><div class='spreadleft'>免费制作游戏》<a href='http://www.yisutui.com'>易速推</a></div><div class='spreadright' ontouchstart='yisutui.spreadclose()'>×</div>";
                        yisutui__css.innerHTML = ".ystspreadfloat {width: 56%;float: right;position: absolute;bottom: 0.7rem;right: 0px; background-color: rgba(60,60,61,0.5); color: #ffffff; height: 3rem; line-height: 3rem;border-radius: 1.5rem;font-size: 1.4rem;z-index:9996;} .spreadleft {position:relative; width:85%;float: left; text-align:center;} .spreadleft a {color: #09d5f3;font-weight: bold;text-decoration: none;} .spreadright {position:relative;width:15%;float:left;font-size: 2rem;height: 3rem;line-height: 3rem;font-weight: bolder;text-align:left;}";
                        var first = document.body.firstChild;

                        document.body.insertBefore(yisutui__div, first);
                        document.head.appendChild(yisutui__css);
                    }
                }
            },
            failure: function() {
                var yisutui_ = document.getElementById('ystspreadfloat');
                if (!yisutui_) {
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'ystspreadfloat';
                    yisutui__div.innerHTML = "<div class='ystspreadfloat'><div class='spreadleft'>免费制作游戏》<a href='http://www.yisutui.com'>易速推</a></div><div class='spreadright' ontouchstart='yisutui.spreadclose()'>×</div>";
                    yisutui__css.innerHTML = ".ystspreadfloat {width: 56%;float: right;position: absolute;bottom: 0.7rem;right: 0px; background-color: rgba(60,60,61,0.5); color: #ffffff; height: 3rem; line-height: 3rem;border-radius: 1.5rem;font-size: 1.4rem;z-index:9996;} .spreadleft {position:relative; width:85%;float: left; text-align:center;} .spreadleft a {color: #09d5f3;font-weight: bold;text-decoration: none;} .spreadright {position:relative;width:15%;float:left;font-size: 2rem;height: 3rem;line-height: 3rem;font-weight: bolder;text-align:left;}";
                    var first = document.body.firstChild;

                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            }
        });





    }

    //优惠券弹窗关闭 20150828  lbb
    yisutui.coupclose = function() {
        // var yisutui_=document.body;
        // yisutui_.removeChild(yisutui_.childNodes[0]);
        document.getElementById('coupshow').style.display = "none";
    };
    //推广漂浮关闭 20150805 ggb
    yisutui.spreadclose = function() {
        var ystspreadfloat = document.getElementById('ystspreadfloat');
        if (ystspreadfloat) {
            document.getElementById('ystspreadfloat').parentNode.removeChild(document.getElementById('ystspreadfloat'));
        }
    };
    //关注我们弹窗 20151124 ggb
    yisutui.ystspreadtab = function(spreadcode) {
        if (spreadcode !== '' && spreadcode !== "undefined") {
            var wechatcode = domain + "/files/images/" + spreadcode;
        } else {
            var wechatcode = domain + "/API/img/code.png'";
        }
        var yisutui_ = document.getElementById('ystspreadtab');
        if (!yisutui_) {
            var yisutui__div = document.createElement('div');
            var yisutui__css = document.createElement('style');
            yisutui__div.id = 'ystspreadtab';
            yisutui__div.innerHTML = " <div class='ystback' id='ystback'><img class='ystfimg' id='ystwechatcode' src='" + domain + "/API/img/fllow2.png'><img class='ystcimg' src='" + wechatcode + "'></div>";
            yisutui__css.innerHTML = ".ystback{width: 100%;height: 100%;position: fixed;top: 0;left: 0;background-color: rgba(0,0,0,.5);z-index: 9999;}.ystfimg{width: 77%;height: 62%;top: 13%;position: fixed;left: 11.5%;} .ystcimg{width: 50.5%;position: absolute;top: 17%;left: 25%;}";
            var first = document.body.firstChild;

            document.body.insertBefore(yisutui__div, first);
            document.head.appendChild(yisutui__css);
            document.getElementById('ystspreadtab').style.display = "none";
        } else {
            document.getElementById('ystspreadtab').style.display = "block";
        }
        var isOut = true;
        var dom = document.getElementById('ystwechatcode');
        var other = document.getElementById('ystback');
        other.addEventListener("touchstart", function() {
            if (isOut) {
                document.getElementById('ystspreadtab').style.display = "none";
                //document.getElementById('ystspreadtab').parentNode.removeChild(document.getElementById('ystspreadtab'));
                // var ystspreadall=document.body;
                // ystspreadall.removeChild(ystspreadall.childNodes[0]);
            }
            isOut = true;
        }, false);
        dom.addEventListener("touchstart", function() {
            isOut = false;
        }, false);

    }

    window.yisutui = yisutui;
    //设置多少时间执行函数
    var loadVal = 0;
    var load_total = 10;

    var loader = setInterval(
        function() {
            if (++loadVal >= load_total) {
                loader = clearInterval(loader);
            }
            //alert(loadVal);
            // yisutui.progress(loadVal);
        },
        500
    );
    // 获取我的礼物 20151212 by fg
    yisutui.getmygift = function(e) {
        if (e == 1) {
            document.getElementById('coupshow2').style.display = 'block';
            yisutui.getgiftdata();
            return;
        }
        var yisutui_start = document.getElementById('coupshow2');
        if (!yisutui_start) {
            var yisutui_start_div = document.createElement('div');
            var yisutui_start_css = document.createElement('style');
            yisutui_start_div.id = 'coupshow2';
            yisutui_start_div.style.display = 'none';
            yisutui_start_div.innerHTML = "<div class='coupcontainer'><img src='" + domain + "/files/images/" + ystmygift + "' class='yst-gift' style='z-index:1;'><img src='" + domain + "/files/images/" + ystmygift_down + "' class='yst_coupon_mycoupon'><div class='yst_coupon_bg' id='yst_coupon_bg'><img src='" + domain + "/files/images/" + yst_gift_bg + "' class='yst_coupon_bgimg'><div class='yst_coupon_namelist'><div class='yst_coupon_con' id='coupon_addli'></div></div><img src='" + domain + "/files/images/" + yst_gift_colse + "' class='yst_coupon_close' ontouchstart='yisutui.giftclose()'></div></div>";
            yisutui_start_css.innerHTML = ".coupcontainer{z-index: 9999; width: 80%; height: 80%; position: absolute; top: 10%; left: 10%;} .yst_coupon_mycoupon{position: fixed;top: 31%; left: 2%; height: 21%;} .yst_coupon_bg{width: 75%;height: 90%; position: fixed; left: 15%; top: 5%;} .yst_coupon_bgimg{width: 100%; height: 100%;} .yst_coupon_namelist{width: 75%; height: 70%; position: fixed; top: 24%;} .yst_coupon_con{width: 100%; height: 90%; position: relative; top: 0%; overflow-y:auto; } .coupon_container{margin:0; margin-left:10%;padding: 0; color: #925206; font-weight: 600; font-size: 1.5rem;} .coupon_container li{list-style: none; display: block; height: 10%;margin-top:3%;} .yst_coupon_name{margin-top: 5%;} .yst_coupon_s1{margin-left: 6%;} .yst_coupon_s2{position: absolute;right: 18%;} .yst_coupon_close{position: fixed; top: 4%; left: 84%; width: 8%;} .coup{font-size: 1.2rem;color: white;width: 100%;margin-top: 6px;float:left;color:#925206;} .coup1{float: left;width:50%} .coup2{float: right;margin-right:0%;width:50%;text-align:center;}.yst-gift{position: fixed;left: 1%;top: 30%;width: 9%;}";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui_start_div, first);
            document.head.appendChild(yisutui_start_css);
        }
    };
    // 关闭我的奖品页面 20151214 by fg
    yisutui.giftclose = function() {
        var coupshow2 = document.getElementById('coupshow2');
        coupshow2.style.display = "none";
        var coupon_container = document.getElementById('coupon_addli');
        if (coupon_container) {
            coupon_container.innerHTML = "";
        }
    };
    // 抽奖结束data 20151214 lfg
    yisutui.getgiftdata = function() {
        Ajax.request("/g/getmygift", {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {
                var data = JSON.parse(xhr.responseText);
                if (data.code == "1") {
                    var coupon_name = "<ul class='coupon_container'>";
                    for (var o in data.usermsg) {
                        if (!isNaN(parseInt(o))) {
                            if (data['usermsg'][o]['prizename'] != null && data['usermsg'][o]['awardname'] != null && data['usermsg'][o]['prizename'] != "" && data['usermsg'][o]['awardname'] != "") {
                                if (data['usermsg'][o]['prizename'].length > 7) {
                                    data['usermsg'][o]['name'] = data['usermsg'][o]['prizename'].substring(0, 7) + "*";
                                }
                                coupon_name = coupon_name + "<li class='coup1'>" + data['usermsg'][o]['prizename'] + "</li><li class='coup2'>" + data['usermsg'][o]['awardname'] + "</li>";
                            }
                        }
                    }
                    coupon_name = coupon_name + "</ul>";
                    var couponcontain = document.getElementById('coupon_addli');
                    yisutui.append(couponcontain, coupon_name);
                }
            },
            failure: function() {
                alert("数据异常！");
            }
        });
    };
    //游戏结束页面
    yisutui.gameOverLoad = function(score, highscore) {
        var score = parseFloat(score);
        var yisutui_ = document.getElementById('yisutui_');
        if (!yisutui_) {
            var yisutui__div = document.createElement('div');
            var yisutui__css = document.createElement('style');
            yisutui__div.id = 'yisutui_';
            yisutui__css.innerHTML = "html{font-size: 10px;} @media screen and (min-width:480px) and (max-width:639px) {html {font-size: 15px}} @media screen and (min-width:640px) and (max-width:719px) { html {font-size: 20px}} @media screen and (min-width:720px) and (max-width:749px) {html {font-size: 22.5px}} @media screen and (min-width:750px) and (max-width:799px) {html {font-size: 23.5px}} @media screen and (min-width:800px) and (max-width:959px) {html {font-size: 25px}} @media screen and (min-width:960px) and (max-width:1079px) {html {font-size: 30px}} @media screen and (min-width:1080px) {html {font-size: 32px}} .yst-gameOver-container{width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:9998;}.gameOverUI{width: 100%;position:relative;} .yst-portrait{width: 27%;border-radius: 100%;left: 36.5%;top: 5%;position: fixed;} .yst-gameover{width: 73%;left: 13.5%;top: 22%;position: fixed;}.yst-score-item{color: #fff;text-align: left;font-size: 1.7rem;width: 54%;margin: auto;position: fixed;left: 22%;top: 32%;font-family: Microsoft YaHei,Helvetica,Tahoma;} .yst-bestscore{color: #fff;font-size: 1.7rem;width: 60%;margin: auto;overflow: auto;zoom: 1;position: fixed;left: 22%;top: 39%;font-family: Microsoft YaHei,Helvetica,Tahoma;} .yst-bestscore li,.yst-bestrank li{float: left;list-style-type: none;} .yst-bestrank{color: #fff;font-size: 1.7rem;text-align: center;width: 60%;margin: auto;overflow: auto;zoom: 1;position: fixed;left: 22%;top: 43%;font-family: Microsoft YaHei,Helvetica,Tahoma;}.yst-item{width: 70%;margin: auto;overflow: auto;position: fixed;left: 15%;top: 51%;} .yst-rank{width:46%;float:left;} .yst-restart{width: 46%;float:left;margin-left:4%;} .prize-tip{text-align: center;color: #fff;font-size: 1.7rem;position: fixed;top: 60%;width: 100%;} .yst-prize{width: 48%;position: fixed;top: 66%;left: 26%;height: 5.584%;}.yst-fllow{width: 48%;position: fixed;height: 5.584%;top: 76%;left: 26%;} .yst-guide{position: fixed;right: 2%;top: 0;width: 20%;} .ystspread {text-align: center;font-size: 1.4rem;line-height: 3rem;height: 3rem;margin-top:3rem;}.end-bg{position:fixed;width:100%;height:100%;left:0;top:0;}";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui__div, first);
            document.head.appendChild(yisutui__css);
            //获取营销方式
            Ajax.request("/g/get_marketing", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    //判断是否去除版权
                    if (parseInt(data.dellink) == 1) {
                        var spread = "";
                    } else if (parseInt(itemid) == 1356 || parseInt(itemid) == 3510 || parseInt(itemid) == 3643 || parseInt(itemid) == 5053) {
                        var spread = "<a id='ystspread-a' href='http://www.yisutui.com' style='color: #fff;text-decoration: none;'><div class='ystspread'style='position: fixed;bottom: 4%;width: 100%;color: #32c3f9;font-family: Microsoft YaHei,Helvetica,Tahoma;font-size: 15px;'>技术支持：易速推</div></a>";
                    } else {
                        var spread = "<a id='ystspread-a' href='http://www.yisutui.com' style='color: #fff;text-decoration: none;'><div class='ystspread' style='position: fixed;bottom: 4%;width: 100%;color: #32c3f9;font-family: Microsoft YaHei,Helvetica,Tahoma;font-size: 15px;'>免费制作游戏 》易速推</div></a>";
                    }
                    //是否有上传关注图标
                    if (data.endpic !== '' && data.endpic !== undefined) {
                        var endpic = domain + '/files/images/' + data.endpic;
                    } else {
                        var endpic = domain + '/API/img/fllow.png';
                    }
                    //是否设置跳转链接

                    if (data.endtext !== '') {
                        var endtext = data.endtext;
                    } else {
                        var endtext = 'http://www.yisutui.com';
                    }
                    //推广方式
                    if (parseInt(data.spreadtype) == 2) { //关注我们
                        if (data.wechatcode != '') {
                            var wechatcode = String(data.wechatcode);
                        } else {
                            var wechatcode = "";
                        }
                        var spreadtype = "<img src='" + endpic + "' class='yst-fllow' ontouchstart=yisutui.ystspreadtab('" + wechatcode + "')>";
                        yisutui.ystspreadtab(wechatcode);
                    } else if (parseInt(data.spreadtype) == 3) { //页面跳转
                        var spreadtype = "<a href='" + endtext + "' style='color: #fff;text-decoration: none;'><img src='" + endpic + "' class='yst-fllow'></a>";
                    } else { //隐藏
                        var spreadtype = "";
                    }
                    //是否开启分享限制
                    if (parseInt(data.ishare) == 2) {
                        var sharelimit = "," + data.hitnum + "次游戏机会";
                        var sharelimit2 = "<p class='prize-tip'>剩余游戏次数：" + data.hitnum + "次</p>";
                        var gamemore = data.hitnum + "," + data.addnum;
                    } else {
                        var sharelimit = "";
                        var sharelimit2 = "";
                        var gamemore = "";
                    }
                    //获取结束页面相关图片设置
                    if (parseInt(data.picset) == 1) { //有设置结束页面的相关图片
                        var ystgameover = data.itempic.ystgameover;
                        var ystguide = data.itempic.ystguide;
                        var ystrank = data.itempic.ystrank;
                        var ystrestart = data.itempic.ystrestart;
                        var ystprize = data.itempic.ystprize;
                        var ystgift = data.itempic.mygifticon;
                        var ystcoupon = data.itempic.ystcoupon;
                        var ystsignup = data.itempic.ystsignup;
                        var ystmred = data.itempic.ystmred;
                        var redrank = data.itempic.redrank;
                        var ysttoken = data.itempic.ysttoken;
                        var tokenback = data.itempic.tokenback;
                        //我的奖品图片
                        ystmygift = data.itempic.mygifticon;
                        ystmygift_down = data.itempic.mygifttext;
                        yst_gift_bg = data.itempic.mygiftbg;
                        yst_gift_colse = data.itempic.mygiftclose;
                        //我的优惠券图片
                        mycouponbg = data.itempic.mycouponbg;
                        mycouponclose = data.itempic.mycouponclose;
                        mycouponicon = data.itempic.mycouponicon;
                        mycoupontext = data.itempic.mycoupontext;
                        var endbg = data.itempic.gameoverbg; // 结束页面背景
                        //排行榜活动规则相关图片
                        rankrulebg = data.itempic.rankrulebg;
                        rankruleicon = data.itempic.rankruleicon;
                        rankruleclose = data.itempic.rankruleclose;
                        rankruleback = data.itempic.rankruleback;
                        rankruleleft = data.itempic.rankruleleft;
                        rankruleright = data.itempic.rankruleright;
                        rankruleshadow = data.itempic.rankruleshadow;
                        //兑奖相关图片
                        cashprizetopbg = data.itempic.cashprizetopbg;
                        cashprizebg = data.itempic.cashprizebg;
                        cashprizesubmit = data.itempic.cashprizesubmit;
                        //报名表单相关图片
                        enrolltopbg = data.itempic.enrolltopbg;
                        enrollbg = data.itempic.enrollbg;
                        enrollsubmit = data.itempic.enrollsubmit;
                    } else { //没设置
                        var ystgameover = "ystgameover.png";
                        var ystguide = "ystguide.png";
                        var ystrank = "ystrank.png";
                        var ystrestart = "ystrestart.png";
                        var ystprize = "ystprize.png";
                        var ystgift = "mygifticon.png";
                        var ystcoupon = "ystcoupon.png";
                        var ystsignup = "ystsignup.png";
                        var ystmred = "ystmred.png";
                        var redrank = "redrank.png";
                        var ysttoken = "ysttoken.png";
                        var tokenback = "tokenback.png";
                        //我的奖品图片
                        ystmygift = "mygifticon.png";
                        ystmygift_down = "mygifttext.png";
                        yst_gift_bg = "mygiftbg.png";
                        yst_gift_colse = "mygiftclose.png";
                        //我的优惠券图片
                        mycouponbg = "mycouponbg.png";
                        mycouponclose = "mycouponclose.png";
                        mycouponicon = "mycouponicon.png";
                        mycoupontext = "mycoupontext.png";
                        var endbg = "gameoverbg.png"; // 结束页面背景
                        //排行榜活动规则相关图片
                        rankrulebg = "rankrulebg.png";
                        rankruleicon = "rankruleicon.png";
                        rankruleclose = "rankruleclose.png";
                        rankruleback = "rankruleback.png";
                        rankruleleft = "rankruleleft.png";
                        rankruleright = "rankruleright.png";
                        rankruleshadow = "rankruleshadow.png";
                        //兑奖相关图片
                        cashprizetopbg = "cashprizetopbg.png";
                        cashprizebg = "cashprizebg.png";
                        cashprizesubmit = "cashprizesubmit.png";
                        //报名表单相关图片
                        enrolltopbg = "enrolltopbg.png";
                        enrollbg = "enrollbg.png";
                        enrollsubmit = "enrollsubmit.png";
                    }
                    if (data.marketing == "0") { //抽奖
                        yisutui.getmygift(0);
                        yisutui__div.innerHTML = "<div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item' style='-webkit-user-select:none;user-select:none;'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore' style='-webkit-user-select:none;user-select:none;'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank' style='-webkit-user-select:none;user-select:none;'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'><img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'><img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='prizenum'></span><span id='gamenum'></span></p><img src='" + domain + "/files/images/" + ystprize + "' class='yst-prize' id='gamegetprize'><img src='" + domain + "/files/images/" + ystgift + "' class='yst-gift' ontouchstart='yisutui.getmygift(1)'><img src='' class='yst_coupon_mycoupon'>" + spreadtype + "</div>" + spread + "</div>";
                    } else if (data.marketing == "1") { //优惠券
                        yisutui.gameCoupons();
                        yisutui__div.innerHTML = "<div class='yst_coupon_gift' ontouchstart='yisutui.coupshow()'><img src='" + domain + "/files/images/" + mycouponicon + "' class='yst_coupon_gift' id='yst_coupon_gift'></div><div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'><img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'><img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='prizenum'></span><span id='gamenum'></span></p><img src='" + domain + "/files/images/" + ystcoupon + "' class='yst-prize' id='getcoupon'>" + spreadtype + "</div>" + spread + "</div>";
                        yisutui.coupshow(); //预加载我的优惠券页面                        
                    } else if (data.marketing == "2") { //表单
                        yisutui__div.innerHTML = "<div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'><img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'><img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='gamenum'></span></p><img src='" + domain + "/files/images/" + ystsignup + "' id='getmform' class='yst-prize' ontouchstart='yisutui.mform()'>" + spreadtype + "</div>" + spread + "</div>";
                    } else if (data.marketing == "3") { //排行榜
                        marketing = data.marketing;
                        yisutui__div.innerHTML = "<div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'><img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'><img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='gamenum'></span></p><img src='" + domain + "/files/images/" + ystsignup + "' id='getmform' class='yst-prize' ontouchstart='yisutui.typeform()'>" + spreadtype + "</div>" + spread + "</div>";
                        yisutui.rankrule(); //预加载排行榜活动规则
                    } else if (data.marketing == "5") { //微信红包
                        yisutui.getmyred(); //预加载我的红包页面
                        Ajax.request('/g/show_redlist',{
                            async: true,
                            method: "POST",
                            encode: "UTF-8",
                            data: {
                                itemid: itemid
                            },
                            success:function(xhr){
                                var red_data=JSON.parse(xhr.responseText);
                                var str="";
                                if(red_data.status==1){
                                    str="<img src='" + domain + "/files/images/" + redrank + "' class='yst-rank' ontouchstart='yisutui.itemred()'>";
                                }else{
                                    str="<img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'>";
                                }
                                yisutui__div.innerHTML = "<div class='yst_coupon_gift' ontouchstart='yisutui.coupshow()'><img src='" + domain + "/files/images/" + mycouponicon + "' class='yst_coupon_gift' id='yst_coupon_gift'></div><div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item' style='-webkit-user-select:none;user-select:none;'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore' style='-webkit-user-select:none;user-select:none;'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank' style='-webkit-user-select:none;user-select:none;'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'>"+str+"<img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='prizenum'></span><span id='gamenum'></span></p><img src='" + domain + "/files/images/" + ystmred + "' class='yst-prize' id='getmred'>" + spreadtype + "</div>" + spread + "</div>";
                            }
                        });
                        yisutui.gamered(); //预加载我的红包页面  
                        yisutui.itemred(); //预加载红包总榜                         
                    } else if (data.marketing == "6") { // 口令红包入口
                        // console.log("口令红包入口");
                        Ajax.request('/g/show_redlist',{
                            async: true,
                            method: "POST",
                            encode: "UTF-8",
                            data: {
                                itemid: itemid
                            },
                            success:function(xhr){
                                var red_data=JSON.parse(xhr.responseText);
                                var str="";
                                if(red_data.status==1){
                                    str="<img src='" + domain + "/files/images/" + redrank + "' class='yst-rank' ontouchstart='yisutui.itemred()'>";
                                }else{
                                    str="<img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'>";
                                }
                                yisutui__div.innerHTML = "<div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item' style='-webkit-user-select:none;user-select:none;'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore' style='-webkit-user-select:none;user-select:none;'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank' style='-webkit-user-select:none;user-select:none;'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'>"+str+"<img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='prizenum'></span><span id='gamenum'></span></p><img src='" + domain + "/files/images/" + ysttoken + "' class='yst-prize' id='gamegetprize' ontouchstart='yisutui.getmycommend()'>" + spreadtype + "</div>" + spread + "</div>";
                            }
                        });
                        
                    } else { //仅分享
                        yisutui__div.innerHTML = "<div class='yst-gameOver-container'><img src='" + domain + "/files/images/" + endbg + "' class='end-bg'><div class='gameOverUI'><img src='" + data.avatar + "' class='yst-portrait'><img src='" + domain + "/files/images/" + ystgameover + "' class='yst-gameover'><div class='yst-score-item'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore'><li>最佳成绩为：</li><li id='bestscore'></li></div><div class='yst-bestrank'><li>最佳排名为：</li><li id='bestrank'></li></div><div class='yst-item'><img src='" + domain + "/files/images/" + ystrank + "' class='yst-rank' ontouchstart='yisutui.itemrank()'><img src='" + domain + "/files/images/" + ystrestart + "' id='gamemore' class='yst-restart'></div><p class='prize-tip' style='-webkit-user-select:none;user-select:none;'><span id='gamenum'></span></p>" + spreadtype + "</div>" + spread + "</div>";
                    }
                },
                failure: function() {
                    yisutui__div.innerHTML = "<div class='yst-gameOver-container'><img src='" + domain + "/files/images/endbg.png' class='end-bg'><img src='" + domain + "/files/images/ystguide.png' class='yst-guide'><div class='gameOverUI'><img src='http://wx.qlogo.cn/mmopen/ca1q0tATXbk1fmNLW2xjOLDZLpPcU9xic4WicZLdmfFFps6mtblN3VTCUwCicow2ibnG6m3DEOIqdNrgAy7IGSLj4ZYqe1fShDSU/0' class='yst-portrait'><img src='" + domain + "/files/images/ystgameover.png' class='yst-gameover'><div class='yst-score-item'>当前我的成绩：<span id='yst-score'>" + score + "</span></div><div class='yst-bestscore'><li>最佳成绩为：</li><li id='bestscore'>" + score + "</li></div><div class='yst-bestrank'><li>最佳排名为：</li><li id='bestrank'>暂无</li></div><div class='yst-item'><img src='" + domain + "/files/images/ystrank.png' class='yst-rank' ontouchstart='yisutui.itemrank()'><img src='" + domain + "/files/images/ystrestart.png' ontouchstart='yisutui.more(" + gamemore + ")' class='yst-restart'></div></div><a href='http://mp.weixin.qq.com/s?__biz=MzI1MDAzMDY0Nw==&mid=208426446&idx=1&sn=192b70a408f730da2366a6ba0c3e5906#rd' style='color: #fff;text-decoration: none;'><div class='ystspread' style='position: fixed;bottom: 4%;width: 100%;color: #32c3f9;font-family: Microsoft YaHei,Helvetica,Tahoma;font-size: 15px;-webkit-user-select:none;user-select:none;'>免费制作游戏 》易速推</div></a></div>";
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            });

        }
        document.getElementById('yisutui_').style.display = "none";
    };
    //口令红包   20160222    hjk
    yisutui.getmycommend = function() {
        var isbarrage=document.getElementById('yst-barrage-mask');
        if(isbarrage){
            isbarrage.style.display="none";
        }
        var yisutui_start = document.getElementById('redcommend');
        if (!yisutui_start) {
            Ajax.request('/g/create_token', {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: { itemid: itemid, score: gamescore },
                success: function(xhr) {

                    var data = JSON.parse(xhr.responseText);
                    if(data.status==2){
                        var tip=data.tip;
                        if(tip == ""){
                            tip="得分不足";
                        }
                        alert(tip);
                        return;
                    }
                    var yisutui__div = document.createElement('div');
                    var yisutui__css = document.createElement('style');
                    yisutui__div.id = 'redcommend';
                    yisutui__div.innerHTML = "<div class='yst-get-passwordred'><div class='yst-passwordred-top'><div  id='yst-passwordred-text' class='yst-passwordred-text'>" + data.token + "</div></div><div class='yst-passwordred-qr'><img src='" + data.qrcodeurl + "'></div><div class='yst-passwordred-bottom'><p>领取说明:</p><div class='yst-receive-con'>" + data.gettip + "</div></div><img src='" + domain + "/files/images/tokenback.png' class='redcom-back' ontouchstart='yisutui.wordredback()'></div>";
                    yisutui__css.innerHTML = "html{font-size:62.5%;}a, p, span, ul, ol, li, td {-webkit-tap-highlight-color: rgba(0, 0, 0, 0);padding: 0;margin: 0;list-style-type: none;text-decoration: none;}body{background: #fff;margin: 0;}.yst-get-passwordred{width: 100%;height: 100%;position: fixed;left: 0;top: 0;z-index:99999;background-color:#fff}.yst-passwordred-top{width: 100%;height: 30%;text-align: center;background:url(/API/img/wordbg.png);background-size: 100% 100%;position:relative}.yst-passwordred-text{background-color:#fff;line-height:30px;width: 41%;height: 30px;outline: none;border: 0;border-radius: 12px;font-size: 1.4rem;text-align: center;padding: 0.5% 3% 0;color: #666;display: inline-block;font-weight: bold;position:absolute;top:41%;left:25%}.yst-passwordred-btn{border: 0;height: 100%;width: 25%;border-radius: 10px;background:yellow;color:red;margin-left:1%;outline:none;}.yst-passwordred-qr{text-align:center;margin-top:8%;height:30%;padding-bottom:8%;width:70%;margin-left:15%;border-bottom:1px dashed #fe514a;}.yst-passwordred-qr img{height:100%;}.yst-passwordred-bottom{margin-top:8%;width:100%;height:15%;}.yst-passwordred-bottom p{margin-left:10%; width:80%; font-size:1.6rem;color:#000;font-weight: bold;}.redcom-back{width: 40%;margin: 0% 30% 0px;position:fixed;bottom:5%}.yst-receive-con{width: 80%;margin-left: 10%;margin-top: 5px;font-size: 1.3rem;text-indent:2em;}";
                    var first = document.body.firstChild;
                    document.body.insertBefore(yisutui__div, first);
                    document.head.appendChild(yisutui__css);
                }
            });
        }else{
           // var gamegetprize=document.getElementById('gamegetprize');
           //  gamegetprize.addEventListener("touchstart", yisutui.moreclicktip, false); 
           alert("亲~每次游戏结束后，只能领取一次口令");
        }

        
    }

    yisutui.wordredback=function(){
        var isbarrage=document.getElementById('yst-barrage-mask');
        if(isbarrage){
            isbarrage.style.display="block";
        }
        var ystspread=document.getElementById('ystspread-a');
        if(ystspread){
            ystspread.setAttribute('href','#');
            setTimeout(function(){
                ystspread.setAttribute('href','http://www.yisutui.com');
            },1000);
        }
        var redcom=document.getElementById('redcommend');
        redcom.style.display='none';
    }
    //我的红包   20160116    ggb
    yisutui.getmyred = function() {
        var yisutui_start = document.getElementById('getmyred');
        if (!yisutui_start) {
            var yisutui_start_div = document.createElement('div');
            var yisutui_start_css = document.createElement('style');
            yisutui_start_div.id = 'getmyred';

            yisutui_start_div.innerHTML = "<div class='packet-close' id='closeBtn' ontouchstart='yisutui.myredclose()'><img src='" + domain + "/API/img/closePac.png'></div><div class='packet-container' id='packet-container'><div class='packet-roll'><div class='packet-hid' id='packet-hid'></div></div></div>";
            yisutui_start_css.innerHTML = ".packet-container {background-image: url(" + domain + "/API/img/packetBg.png);background-repeat: no-repeat;background-size: 100% 100%;width: 80%;height: 89%;left: 13.59%;top: 4.37%;position: absolute;display: block;z-index: 10002;} .packet-close {position: absolute;right: 4.68%;top: 3.6%;width: 7.34%;z-index: 10003;display: block;} .packet-close img {width: 100%;} .packet-content {width: 104%;height: 100%;overflow-y: auto;overflow-x: hidden;position: absolute;} .myPacket {width: 100%;border-bottom: 1px solid #a33e3a;height: 35px;line-height: 35px;} .enter-momey {text-align: center;width: 35%;color: #fff;font-size: 15px;float: left;text-indent: 5%;} .enter-time {font-size: 13px;float: right;color: #fff;margin-right: 10px;} .packet-roll {width: 80%;height: 55%;left: 13.5%;top: 31.58%;position: fixed;} .packet-hid {position: absolute;left: 8.5%;width: 84%;height: 100%;overflow: hidden;}";

            var first = document.body.firstChild;

            document.body.insertBefore(yisutui_start_div, first);
            document.head.appendChild(yisutui_start_css);
            Ajax.request("/g/getmyred", {
                async: true,
                method: "POST",
                encode: "UTF-8",
                data: {
                    itemid: itemid
                },
                success: function(xhr) {
                    var data = JSON.parse(xhr.responseText);
                    if (data.code == "1") {
                        var coupon_name = "<div class='packet-content'>";
                        for (var o in data.red) {
                            if (!isNaN(parseInt(o))) {
                                coupon_name = coupon_name + "<div class='myPacket'><div class='enter-momey'><span>" + data['red'][o]['redamount'] + "</span>元</div><div class='enter-time'><span>" + data['red'][o]['addtime'] + "</span></div></div>";
                            }
                        }
                        coupon_name = coupon_name + "</div>";
                        var couponcontain = document.getElementById('packet-hid');
                        yisutui.append(couponcontain, coupon_name);
                    }
                },
                failure: function() {
                    alert("网络异常，请再试一下！");
                }
            });
            document.getElementById('getmyred').style.display = "none";
        } else {
            document.getElementById('getmyred').style.display = "block";
        }
    };
    //优惠券弹窗关闭 20150828  lbb
    yisutui.myredclose = function() {
        // var yisutui_=document.body;
        // yisutui_.removeChild(yisutui_.childNodes[0]);
        document.getElementById('getmyred').style.display = "none";
    };
    //我的红包悬浮块 20160116 ggb
    yisutui.gamered = function() {
        var yisutui_start = document.getElementById('gamered');
        if (!yisutui_start) {
            var yisutui_start_div = document.createElement('div');
            var yisutui_start_css = document.createElement('style');
            yisutui_start_div.id = 'gamered';
            yisutui_start_css.innerHTML = ".packet-left {position: absolute;left: 1.4%;top: 28.31%;width: 8.59%;z-index: 9999;} .packet-left img {width: 100%;} .packet-left span {display: block;width: 50%;background-color: #bf403a;color: #fff;font-size: 13px;text-align: center;border-radius: 50px;padding: 60% 5% 60% 5%;margin-left: 20%;margin-top: -60%;display: none;}";
            yisutui_start_div.innerHTML = "<div class='packet-left' ontouchstart='yisutui.getmyred()'><img src='" + domain + "/API/img/packetIcon.png' ontouchstart=><span id='left-text'>我的红包</span></div>";
            var first = document.body.firstChild;
            document.body.insertBefore(yisutui_start_div, first);
            document.head.appendChild(yisutui_start_css);
        }
    };
    //弹幕    20160220 hjk
    var screen_wid = document.documentElement.clientWidth;
    var screen_hei = document.documentElement.clientHeight;
    var barrage;
    var span_Id1;
    var span_Id2;
    var span_Id3;
    var span_Id4;
    var span_Id5;
    var span_Id6;
    var span_Id7;
    var span_Id8;
    var span_Id9;
    var span_IdAdd;
    var span_Id;
    var colorContent;
    var clickImg;
    var input_content;
    var count = 0;
    var isShow = false;
    var fontColor = "ffffff";
    var dataArray = [];
    var colorArray = [];
    var initTimecount = 0;
    var timecount1 = 0;
    var timecount2 = 0;
    var timecount3 = 0;
    var timecount4 = 0;
    var isfirst = true;
    var iscontent = true;
    var addTextArr = [];
    var clicktime = 1;
    var timecount = 0;
    var dataLength=0;

    yisutui.barrageData = function() {
        Ajax.request('/g/get_comments', {
            async: true,
            method: "POST",
            encode: "UTF-8",
            data: {
                itemid: itemid
            },
            success: function(xhr) {

                var data = JSON.parse(xhr.responseText);
                if (data.code == 1) {
                    console.log(1111)
                    if (data.status == 1) {
                        dataArray = [];
                        colorArray = [];
                        dataLength=data.content.length;
                        for (var i = 0; i < data.content.length; i++) {
                            dataArray.push(data.content[i].content);
                            colorArray.push(data.content[i].fontcolor);
                        }
                        if (dataArray.length % 9 != 0) {
                            for (var i = 0; i < dataArray.length % 9; i++) {
                                dataArray.push(dataArray[i]);
                                colorArray.push(colorArray[i]);
                            }
                        }
                        if (iscontent) {
                            yisutui.barrageContent();
                            iscontent = false;
                        }
                        if (isfirst) {
                            var initTimer = setInterval(function() {
                                if (initTimecount > 1) {
                                    clearInterval(initTimer);
                                    yisutui.barinit();
                                    initTimecount = 0;
                                } else {
                                    initTimecount++;
                                }
                            }, 1000);
                            isfirst = false;
                        }
                    }
                    if (data.status == 2) {
                        for(var i=0;i<9;i++){
                            dataArray.push("");
                            colorArray.push("ffffff");
                        }
                        dataArray[0]="赶紧来抢沙发哦！";
                        dataArray[3]="赶紧来抢沙发哦！";
                        dataArray[6]="赶紧来抢沙发哦！";
                        if (iscontent) {
                            yisutui.barrageContent();
                            iscontent = false;
                        }
                        if (isfirst) {
                            var initTimer = setInterval(function() {
                                if (initTimecount > 1) {
                                    clearInterval(initTimer);
                                    yisutui.barinit();
                                    initTimecount = 0;
                                } else {
                                    initTimecount++;
                                }
                            }, 1000);
                            isfirst = false;
                        }
                    }


                }
                if (data.code == 2) {
                    console.log("未开启弹幕");
                }
            }
        });
    }
    yisutui.barinit = function() {
        span_Id1 = document.getElementById("fly1");
        span_Id2 = document.getElementById("fly2");
        span_Id3 = document.getElementById("fly3");
        span_Id4 = document.getElementById("fly4");
        span_Id5 = document.getElementById("fly5");
        span_Id6 = document.getElementById("fly6");
        span_Id7 = document.getElementById("fly7");
        span_Id8 = document.getElementById("fly8");
        span_Id9 = document.getElementById("fly9");
        span_IdAdd = document.getElementById("addFly");
        span_Id = [span_Id1, span_Id2, span_Id3, span_Id4, span_Id5, span_Id6, span_Id7, span_Id8, span_Id9, span_IdAdd];
        for (var i = 0; i < 10; i++) {
            span_Id[i].style.left = screen_wid + "px";
        }
        yisutui.control_fly(0, "show");
        var timer1 = setInterval(function() {
            if (timecount1 >= 25) {
                yisutui.fly_change(1);
                clearInterval(timer1);
                timecount1 = 0;
            } else {
                timecount1++;
            }
        }, 100);
    }
    yisutui.fly_change = function(num) {
        switch (num) {
            case 1:
                yisutui.control_fly(1, "show");
                var timer1 = setInterval(function() {
                    if (timecount1 >= 25) {
                        yisutui.control_fly(0, "hide");
                        yisutui.fly_change(2);
                        clearInterval(timer1);
                        timecount1 = 0;
                    } else {
                        timecount1++;
                    }
                }, 100);
                break;
            case 2:
                yisutui.control_fly(2, "show");
                count++;
                if (count >= dataArray.length / 9) {
                    count = 0;
                }
                var timer2 = setInterval(function() {
                    if (timecount2 >= 25) {
                        yisutui.control_fly(1, "hide");
                        yisutui.fly_change(3);
                        clearInterval(timer2);
                        timecount2 = 0;
                    } else {
                        timecount2++;
                    }
                }, 100);
                break;
            case 3:
                yisutui.control_fly(0, "show");
                var timer3 = setInterval(function() {
                    if (timecount3 >= 25) {
                        yisutui.control_fly(2, "hide");
                        yisutui.fly_change(1);
                        clearInterval(timer3);
                        timecount3 = 0;
                    } else {
                        timecount3++;
                    }
                }, 100);
        }
    }
    yisutui.control_fly = function(num, str) {
        if (str == "show") {
            for (var i = 0; i < 3; i++) {
                span_Id[i + num * 3].innerHTML = dataArray[i + num * 3 + count * 9];
                span_Id[i + num * 3].style.color = "#" + colorArray[i + num * 3 + count * 9];
                span_Id[i + num * 3].className = span_Id[i + num * 3].className.replace("displ", "barrage" + (i + 1 + num * 3));
            }
        } else {
            for (var i = 0; i < 3; i++) {
                span_Id[i + num * 3].className = span_Id[i + num * 3].className.replace("barrage" + (i + 1 + num * 3), "displ");
            }
        }
    }

    yisutui.barrageContent = function() {
        var yst_barrage_div = document.createElement('div');
        yst_barrage_div.className = 'yst-barrage-show';
        var yst_barrage_div = document.createElement('div');
        yst_barrage_div.className = 'yst-barrage-show';
        yst_barrage_div.innerHTML = '<div class="yst-barrage-fly" id="yst-barrage-mask"><p><span id="fly1" class="URL-fly displ" style="top:10px;"></span></p><p><span id="fly2" class="URL-fly displ" style="top:30px;"></span></p><p><span id="fly3" class="URL-fly displ" style="top:50px;"></span></p><p><span id="fly4" class="URL-fly displ" style="top:10px;"></span></p><p><span id="fly5" class="URL-fly displ" style="top:30px;"></span></p><p><span id="fly6" class="URL-fly displ" style="top:50px;"></span></p><p><span id="fly7" class="URL-fly displ" style="top:10px;"></span></p><p><span id="fly8" class="URL-fly displ" style="top:30px;"></span></p><p><span id="fly9" class="URL-fly displ" style="top:50px;"></span></p><p><span id="addFly" class="addFly displ"></span></p></div><div class="choose-color-list" id="choose-color-list"><div class="color-list"><div class="color-list-item"><div class="color-item" style="background-color:#fff;" ontouchstart="yisutui.color(1)"><span class="select-status" style="display:block" id="color1"></span></div></div><div class="color-list-item"><div class="color-item" style="background-color:#b90adf;" ontouchstart="yisutui.color(2)"><span class="select-status" id="color2"></span></div></div><div class="color-list-item"><div class="color-item" style="background-color:#13a052;" ontouchstart="yisutui.color(3)"><span class="select-status" id="color3"></span></div></div><div class="color-list-item"><div class="color-item" style="background-color:#f99405;" ontouchstart="yisutui.color(4)"><span class="select-status" id="color4"></span></div></div></div><div class="hide-input" style="float:right;"><img src="' + domain + '/API/img/menu-close-h.png" ontouchstart="yisutui.showInput(5)"></div></div><div class="yst-barrage-content" id="input-content"><table class="yst-barrage-input"><tbody><tr><td class="hide-barrage"><img src="' + domain + '/API/img/menu-barrage.png" ontouchstart="yisutui.showInput(3)" id="clickShow"><p>屏蔽</p></td><td class="currentColor-content"><div class="currentColor" ontouchstart="yisutui.showInput(4)" id="showColor">色</div></td><td><input type="text" placeholder="输入消息" value="" name="" class="barrage-input" id="input-text" maxlength="20"></td><td class="barrage-send-content"><button class="barrage-send" ontouchstart="yisutui.sendMessage()">发送</button></td><td class="hide-input"><img src="' + domain + '/API/img/menu-close-v.png" ontouchstart="yisutui.showInput(2)"></td></tr></tbody></table></div><img src="' + domain + '/API/img/menu.png" class="click-btn" id="click-btn" ontouchstart="yisutui.showInput(1)">';
        document.body.insertBefore(yst_barrage_div, document.body.childNodes[0]);
        var body_style = document.createElement('style');
        body_style.innerHTML = '*{padding:0;margin:0;}body{font:12px/1.14 arial,\5b8b\4f53;color:#333;outline:0;}.yst-barrage-show{position:absolute;font-size:12px;}.yst-barrage-fly{height:80px;overflow:hidden;position:absolute;background:rgba(150,150,150,0.2);z-index:999;}.barrages{position:relative;float:right;}.barrage1{-webkit-animation:barrage1 4.5s  linear;animation:barrage1 4.5s  linear;}.barrage2{-webkit-animation:barrage1 5s  linear;animation:barrage1 5s  linear;}.barrage3{-webkit-animation:barrage1 4s  linear;animation:barrage1 4s  linear;}.barrage4{-webkit-animation:barrage1 5s  linear;animation:barrage1 4.5s  linear;}.barrage5{-webkit-animation:barrage1 4.5s  linear;animation:barrage1 5s  linear;}.barrage6{-webkit-animation:barrage1 4s  linear;animation:barrage1 4s  linear;}.barrage7{-webkit-animation:barrage1 4s  linear;animation:barrage1 4.5s  linear;}.barrage8{-webkit-animation:barrage1 5s  linear;animation:barrage1 5s  linear;}.barrage9{-webkit-animation:barrage1 4.5s  linear;animation:barrage1 4s  linear;}.barrage_add{-webkit-animation:barrage1 4s  linear;animation:barrage1 4s  linear;}.yst-barrage-fly p{position:absolute;height:20px;}.displ{display:block;}.URL-fly,.addFly{float:right;font-size:14px;position:relative;color:red;text-align:center;}.addFly{border:1px solid #aaa;padding:0 5px;}.click-btn{border-radius:100%;position:absolute;z-index:999;}.yst-barrage-content{position:absolute;bottom:0;width:100%;display:none;z-index:9997;}.yst-barrage-input{display:table;background-color:#e9eaec;width:100%;border-spacing:0;}.currentColor-content{width:40px;}.currentColor{width:30px;height:30px;margin:10px 0 10px 10px;line-height:30px;-webkit-border-radius:15px;-moz-border-radius:15px;border-radius:15px;background-color:#fff;text-align:center;}.barrage-input{width:90%;padding:0 0 0 10px;border:1px solid #dedede;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:7px;font-size:14px;background-color:#fff;-webkit-appearance:none;outline:0;line-height:30px;margin-left:10px;}.barrage-send-content{width:74px;}.barrage-send{padding:0 12px;margin:10px;background-color:#fff;color:#333;line-height:30px;border:1px solid #ccc;border-radius:5px;font-size:12px;outline:none;}.hide-input{width:50px;}.hide-input img{width:100%;}.choose-color-list{background-color:#ddd;width:100%;position:absolute;bottom:53px;display:none;z-index:9997;}.color-list{float:left;width:80%;min-height:10px;position:relative;}.color-list-item{position:relative;display:table-cell;}.color-item{width:34px;height:34px;margin:10px 10px;line-height:34px;-webkit-border-radius:17px;-moz-border-radius:17px;border-radius:17px;position:relative;}.select-status{right:-11%;top:8%;width:43%;height:43%;margin:0;display:block;background-image:url(' + domain + '/API/img/font-selected.png);background-size:cover;display:none;}.hide-barrage{width:50px;}.hide-barrage img{width:60%;margin-left:20%;}.hide-barrage p{height:auto;text-align:center;color:#555;position:relative;}@keyframes barrage1  {0% {right: 0%;} 100% {left:-280px;}} @-webkit-keyframes barrage1 {0% {right: 0%;} 100% {left:-280px ;}}';
        //加入Body
        document.head.appendChild(body_style);
        //初始化样式
        document.getElementById("yst-barrage-mask").style.width=screen_wid+"px";
        document.getElementById("click-btn").style.width=screen_wid*0.1+"px";
        document.getElementById("click-btn").style.left=screen_wid*0.01+"px";
        document.getElementById("click-btn").style.top=screen_hei*0.36+"px";
        document.getElementById("input-content").style.width=screen_wid+"px";
        document.getElementById("input-content").style.bottom=-screen_hei+"px";
        document.getElementById("choose-color-list").style.width=screen_wid+"px";
        
    }
    yisutui.showInput = function(num) {
        input_content = document.getElementById("input-content");
        barrage = document.getElementById("yst-barrage-mask");
        clickImg = document.getElementById("clickShow");
        colorContent = document.getElementsByClassName("choose-color-list");
        switch (num) {
            case 1:
                input_content.style.display = "block";
                break;
            case 2:
                input_content.style.display = "none";
                colorContent[0].style.display = "none";
                break;
            case 3:
                if (isShow) {
                    barrage.style.zIndex = "999";
                    clickImg.src = domain + "/API/img/menu-barrage.png";
                    isShow = false;
                } else {
                    barrage.style.zIndex = "-1";
                    clickImg.src = domain + "/API/img/menu-barrage-disabled.png";
                    isShow = true;
                }
                break;
            case 4:
                // colorContent[0].style.bottom = input_content.offsetHeight + "px";
                document.getElementById("choose-color-list").style.bottom=-(screen_hei-document.getElementById("input-content").offsetHeight)+"px";
                colorContent[0].style.display = "block";
                break;
            case 5:
                colorContent[0].style.display = "none";
        }
    }
    yisutui.color = function(num) {
        for (var i = 1; i < 5; i++) {
            document.getElementById("color" + i).style.display = "none";
        }
        document.getElementById("color" + num).style.display = "block";
        switch (num) {
            case 1:
                fontColor = "ffffff";
                break;
            case 2:
                fontColor = "b90adf";
                break;
            case 3:
                fontColor = "13a052";
                break;
            case 4:
                fontColor = "f99405";
                break;
        }
        document.getElementById("showColor").style.backgroundColor = "#" + fontColor;
    }
    yisutui.sendMessage = function() {
        var input_text = document.getElementById("input-text");
        var text = input_text.value;
        document.getElementById("input-text").value = "";
        addTextArr.push(text);
        if (text != "") {
            if (clicktime == 1) {
                Ajax.request('/g/save_comments', {
                    async: true,
                    method: "POST",
                    encode: "UTF-8",
                    data: {
                        itemid: itemid,
                        content: text,
                        fontcolor: fontColor
                    },
                    success: function(xhr) {
                        var data = JSON.parse(xhr.responseText);
                        console.log(data);
                    }
                });
                dataArray[dataLength]=text;
                colorArray[dataLength]=fontColor;
                if (dataArray.length % 9 != 0) {
                    for (var i = 0; i < dataArray.length % 9; i++) {
                        dataArray.push(dataArray[i]);
                        colorArray.push(colorArray[i]);
                    }
                }
                dataLength++;
                var num = Math.round(Math.random() * 2);
                span_IdAdd.innerHTML = text;
                span_IdAdd.style.top = 10 + 20 * num + "px";
                span_IdAdd.style.color = "#" + fontColor;
                document.getElementById("input-text").value = "";
                span_IdAdd.className = span_IdAdd.className.replace("displ", "barrage_add");
                span_IdAdd.addEventListener("animationend", function() { span_IdAdd.className = span_IdAdd.className.replace("barrage_add", "displ"); }, false);
                var timer = setInterval(function() {
                    if (timecount >= 2) {
                        clearInterval(timer);
                        clicktime = 1;
                        timecount = 0;
                    } else {
                        timecount++;
                        clicktime++;
                    }
                }, 1000);
            } else {
                alert("您输入太快了！");
            }

        }
    }

//160311 hjk
yisutui.getmark_cocos=function(games,cc,p_x,p_y){  
            var xmlHttp=new XMLHttpRequest();
            // xmlHttp.open('post','http://www.yisutui.com/y/get_marketing',true);
            xmlHttp.open('post','/g/get_marketing',true);
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send("itemid="+itemid);
            xmlHttp.onreadystatechange=function(){
                if(xmlHttp.readyState==4&&xmlHttp.status==200){
                    var data=JSON.parse(xmlHttp.responseText);
                    switch(data.marketing){
                        case "0":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getprize();}
                            break;
                        case "1":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getcoupon();}
                            break;
                        case "2":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.mform();}
                            break;
                        case "3":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.itemrank();}
                            break;
                        case "5":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getmred();}
                            break;
                        case "5":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getmycommend();}
                            break;
                    }
                    b = new cc.MenuItemImage(res_name,res_name,
                            a_methed,
                            games);
                            b.attr({
                                x: p_x ,
                                y: p_y,
                                anchorX: 0.5,
                                anchorY: 0.5
                            });
                            b = new cc.Menu(b);
                            b.x = 0;
                            b.y = 0;
                            games.addChild(b,5);

                }
            }
}
yisutui.set_rule_cocos=function(games,cc,p_x,p_y){
    a=cc.winSize;
    var rule_btn=new cc.MenuItemImage("rule.png","rule.png",function(){window.parent.yisutui.ruleshow();},games);
    rule_btn.attr({
        x: p_x,
        y: p_y,
        anchorX: 0.5,
        anchorY: 0.5
    });       
    a = new cc.Menu(rule_btn);
    a.x = 0;
    a.y = 0;
    games.addChild(a, 1);
}
yisutui.set_rule_egret=function(games,RES,egret,p_x,p_y){
    RES.getResByUrl('rule.png',function(c){
        games.rulebtn = new egret.Bitmap(c);
        games.rulebtn.anchorOffsetX = games.rulebtn.width / 2;
        games.rulebtn.anchorOffsetY = games.rulebtn.height / 2;
        games.rulebtn.x = p_x;
        games.rulebtn.y = p_y;
        games.rulebtn.touchEnabled = !0;
        games.rulebtn.addEventListener(egret.TouchEvent.TOUCH_BEGIN, function() { yisutui.ruleshow(); }, games);
        games.addChild(games.rulebtn);
    },games,RES.ResourceItem.TYPE_IMAGE);
}
yisutui.getmark_egret=function(games,RES,egret,p_x,p_y){  
            var xmlHttp=new XMLHttpRequest();
            // xmlHttp.open('post','http://www.yisutui.com/y/get_marketing',true);
            xmlHttp.open('post','/g/get_marketing',true);
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlHttp.send("itemid="+itemid);
            xmlHttp.onreadystatechange=function(){
                if(xmlHttp.readyState==4&&xmlHttp.status==200){
                    var data=JSON.parse(xmlHttp.responseText);
                    switch(data.marketing){
                        case "0":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getprize();}
                            break;
                        case "1":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getcoupon();}
                            break;
                        case "2":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.mform();}
                            break;
                        case "3":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.itemrank();}
                            break;
                        case "5":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getmred();}
                            break;
                        case "5":
                            var res_name="jiang.png";
                            var a_methed=function(){yisutui.getmycommend();}
                            break;
                    }
                    RES.getResByUrl(res_name,function(c){
                    games.btn = new egret.Bitmap(c);
                    games.btn.x = p_x;
                    games.btn.y = p_y;
                    games.btn.touchEnabled = !0;
                    games.btn.addEventListener(egret.TouchEvent.TOUCH_BEGIN, a_methed, games);
                    games.addChild(games.btn);
                },games,RES.ResourceItem.TYPE_IMAGE);

                }
            }
}

    yisutui.gamerule();
    yisutui.ystspread();
    yisutui.ruleshow();
    yisutui.gameOverLoad();
    yisutui.addhit();
    yisutui.barrageData();

})();
